Subject: Re: [xsl] how to test previous node name From: "Andrew Welch" <andrew.j.welch@xxxxxxxxx> Date: Mon, 12 Feb 2007 09:40:08 +0000 |
Thank you for your response. I did try this inside template <item> but it fails to get me the right result.
This is what I tried:
<xsl:template match="item"> <xsl:if test="preceding::*[1][self::test1]">
<xsl:text>Found test1</xsl:text> </xsl:if>
</xsl:template>
It is not working.
How do I check if the previous node name for <item> is test1 or text?
<test1> <item></item> <text></text> <item></item> </test1>
The preceding axis gets all nodes before the context node in document order, minus any ancestors:
"the preceding axis contains all nodes that are descendants of the root of the tree in which the context node is found, are not ancestors of the context node, and occur before the context node in document order"
<root> <test1/> <test1> <item></item> <text></text> <item></item> </test1> </root>
<root> <foo><test1/></foo> <test1> <item></item> <text></text> <item></item> </test1> </root>
The reply I gave would give the results you expect - it all depends on how you define the "previous node" for that first <item> child of <test1>.
If you define the previous node to mean the parent node, then just add a test using the parent axis:
(It could well be that you don't want to check the whole preceding axis, just the preceding-sibling axis - its worth figuring that out now based on the examples I've given.)
cheers andrew
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] how to test previous node, Kamal Bhatt | Thread | Re: [xsl] how to test previous node, Abel Braaksma |
RE: [xsl] for-each-group, group-sta, Michael Kay | Date | Re: [xsl] Optimisation -- premature, Andrew Welch |
Month |