[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
> 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/
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|