xsl-list
[Top] [All Lists]

RE: [xsl] An (almost) identity stylesheet

2008-04-10 05:17:12
I know it's embarrassing to post your code when you're a novice, but it's
the best way we have to see where your misunderstandings lie, and therefore
the most efficient way for you to get up the learning curve. This is a very
simple transformation, so there's clearly something basic that you haven't
grasped (which to be honest, is what happens when you try to learn by
blindly copying things - which is the way that some online tutorials try to
teach you).

You can do this with a simple template rule such as

<xsl:template match="date">
  <date attrib1="{(_at_)attrib1}" attrib2="0">
    <xsl:value-of select="."/>
  </date>
</xsl:template>

That assumes of course that when you process the bar element you do the
standard thing of apply-templates to the children, and similarly for foo.

As for recommendations, whenever I have to learn a language the first thing
I do is buy a good book on it. The 4th edition of my XSLT Programmer's
Reference from Wrox comes out in a couple of weeks. The book goes to a lot
of trouble to explain all the basic concepts of the language, as well as the
detailed syntax and semantics.

Michael Kay
http://www.saxonica.com/

-----Original Message-----
From: Karol Krenski [mailto:mimooh(_at_)inf(_dot_)sgsp(_dot_)edu(_dot_)pl] 
Sent: 10 April 2008 09:40
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] An (almost) identity stylesheet

Hi list,

I am a novice to XSLT, learned mainly form online tutorials. This XSLT
thing is killing me. Can't figure out how to transform my doc.xml:

<?xml version="1.0" encoding="UTF-8"?>
<foo>
    <bar>
        <date attrib1='aaaaaaa' attrib2='bbbbbb'>25-02-08</date>
                                         ^
        <name attrib3='null'>AAAAAAAAAAAAAAA</name>
    </bar>
    <bar>
        <date attrib1='cccccc' attrib2='dddddd'>26-02-08</date>
                                        ^
        <name attrib4='null'>BBBBBBBBBBBBBBB</name>
    </bar>
</foo>


into


<?xml version="1.0" encoding="UTF-8"?>
<foo>
    <bar>
        <date attrib1='aaaaaaa' attrib2='0'>25-02-08</date>
                                         ^
        <name attrib3='null'>AAAAAAAAAAAAAAA</name>
    </bar>
    <bar>
        <date attrib1='cccccc' attrib2='0'>26-02-08</date>
                                        ^
        <name attrib4='null'>BBBBBBBBBBBBBBB</name>
    </bar>
</foo>

Can somebody please suggest the correct stylesheet?

I am blindly typing mainly 'copy' or 'copy-of' in my templates and the
output generation mechanics make little sense to me. The docs, comparing
to other programing documentation seems hard to understand. Could
somebody suggest good docs, please?

Regards,
Karol

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>