xsl-list
[Top] [All Lists]

Re: [xsl] Access the same level node with different prefix Index

2007-02-20 13:06:46
Hi
Thanks for correcting me the XML and
I need to get each product node I need to get the respective serial number in the parenthesis. text() might differs so we can that that as criteria of substring and I am wondering ,How I could pass the same node value in the substring argument.
Please advise
Regards,
Senthil

On Feb 20, 2007, at 11:25 AM, Spencer Tickner wrote:

Hello,

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.

Anyway, if your XML is indeed suppose to be:

<?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>

Then:

<?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>

</xsl:stylesheet>

Will produce:

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.

Cheers,

Spencer Tickner




On 2/20/07, Senthilkumaravelan K <skumaravelan(_at_)googlemail(_dot_)com> wrote:
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 .

--~------------------------------------------------------------------
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>
--~--



--~------------------------------------------------------------------
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>