[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
Re: [xsl] Probelm with xsl:value-of in CSV to XML transform
Subject: Re: [xsl] Probelm with xsl:value-of in CSV to XML transform From: Marney Cotterill <marney@xxxxxxxxxxxxxxxxxxxx> Date: Fri, 04 Apr 2008 13:17:20 +1100 |
Thanks Michael, You are right! I am brand new to XML and XSLT and am still getting my head around template rules and how to use them. Sorry for being unclear, my source input is a CSV file, and this problem lies in the second transform template that takes the XML of the converted CSV and adds in the bits and pieces I need to fit the dynamic website I will be importing it to. > The test <xsl:when test="name()='classdate'"> suggests that you haven't yet > learnt how to use template rules, which is the core construct for > structuring XSLT code. When you have conditional logic in the stylesheet > that performs different processing for different elements, create a template > rule for each kind of element and invoke it using xsl:apply-templates. The XSLT stylesheet at the bottom of the first post is almost complete, do you see any errors that may arise in the future by keeping it as <xsl:when...>? Kindest Regards, Marney On 4/4/08 1:10 PM, "Michael Kay" <mike@xxxxxxxxxxxx> wrote: >> I am converting a CSV into XML, and wanted to transform the >> following two tags: >> <classdate>9/03/2008</classdate> >> <sortdate>2008-03-09</sortdate> > > I see two elements there with four tags... And I don't see any > comma-separated values! >> >> Into: >> <classdate> >> <items> >> <item> >> <label>9/03/2008</label> >> <value>2008-03-09</value >> </item> >> </items> >> </classdate> >> >> Where the <sortdate> value becomes the <value> of the <classdate> >> >> I am almost there, but can't get the value of the <sortdate> >> to appear in the <value> tag. >> >> Here is the relevant section of the XSLT: >> <xsl:when test="name()='classdate'"> >> <xsl:element name="classdate"> >> <items> >> <item> >> <label> >> <xsl:value-of select="."/> >> </label> >> <value> >> <xsl:value-of select="sortdate"/> >> </value> >> </item> >> </items> >> </xsl:element> >> </xsl:when> >> > > The sortdate isn't a child of the classdate, it is a sibling. So you want > > <xsl:value-of select="following-sibling::classdate[1]"/> > > (I've added the [1] because your snippet of the input doesn't tell me if > there are any other following siblings) > > The test <xsl:when test="name()='classdate'"> suggests that you haven't yet > learnt how to use template rules, which is the core construct for > structuring XSLT code. When you have conditional logic in the stylesheet > that performs different processing for different elements, create a template > rule for each kind of element and invoke it using xsl:apply-templates. > > Also, <xsl:element name="classdate"> is best replaced by <classdate>. > > Michael Kay > http://www.saxonica.com/ > > Marney Cotterill graphic designer cracker//brandware 6 Bourke Street Queens Park NSW 2022 Telephone 02 9387 2001 Facsimile 02 9387 2006 marney@xxxxxxxxxxxxxxxxxxxx www.crackerbrandware.com
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Probelm with xsl:value-of, Michael Kay | Thread | RE: [xsl] Probelm with xsl:value-of, Michael Kay |
RE: [xsl] Probelm with xsl:value-of, Michael Kay | Date | RE: [xsl] Probelm with xsl:value-of, Michael Kay |
Month |