Subject: Re: [xsl] Access the same level node with different prefix Index From: "Spencer Tickner" <spencertickner@xxxxxxxxx> Date: Tue, 20 Feb 2007 11:25:49 -0800 |
Your XML is invalid.. So I had to make a few assumptions.. Mainly that the match is based on the elements name,, not the text() within the element. I rattled it off quickly so I'm sure there is a nicer solution out there.
<?xml version="1.0"?> <record> <product1>Item1</product1> <product2>Item2</product2> <product3>Item3</product3> <serial1>serial 1</serial1> <serial2>serial 2</serial2> <serial3>serial 3</serial3> </record>
<?xml version='1.0'?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="record"> <xsl:apply-templates select="*[contains(name(), 'product')]"/> </xsl:template>
<xsl:template match="*[contains(name(), 'product')]"> <xsl:variable name="serialNum" select="concat('serial', substring-after(., 'Item'))"/> <xsl:value-of select="."/><xsl:apply-templates select="following-sibling::*[contains(name(), $serialNum)]"/> </xsl:template>
<xsl:template match="*[contains(name(), 'serial')]">(<xsl:value-of select="."/>)<xsl:text> </xsl:text></xsl:template>
Item1(serial 1) Item2(serial 2) Item3(serial 3)
However, if the relationship is based on text() then you'll have to replace name() with text() and 'product' with 'Item' and tweek at match.
Hi All, I have structure as <record> <product1>Item1</product1> <product2>Item2</product2> <product3>Item2</product2> ...... ...... <serial1>serial 1</serial1> <serial2>serial 2</serial2> <serial3>serial 3</serial1> ..... ......
</record> and I would get an an output as Item1(serial 1) Item2(serial 2) Item3(serial 3) ... I am not sure How I could do the substring and access the value of other node and form the output as mentioned.
Please help me .
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Access the same level node wi, Senthilkumaravelan K | Thread | Re: [xsl] Access the same level nod, Senthilkumaravelan K |
[xsl] Access the same level node wi, Senthilkumaravelan K | Date | Re: [xsl] Access the same level nod, Senthilkumaravelan K |
Month |