[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Probelm with xsl:value-of in CSV to XML transform

Subject: RE: Probelm with xsl:value-of in CSV to XML transform
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Fri, 4 Apr 2008 10:10:27 +0800
RE:  Probelm with xsl:value-of in CSV to XML transform
> 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/

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.