|
Subject: Re: [xsl] Test processing instruction as first preceding sibling From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Tue, 09 Dec 2008 15:33:34 -0500 |
Hi guys,
I have a doubt about testing preceding-sibling processing-instruction. I have this xml:
<root> <child1> child 1 </child1> <?proc?> <child2> child 2 </child2> </root>
And I need to know if child2 has the first preceding-sibling as a processing-instruction. In this case it should return true.
But it isn't true. There is a text node between the processing instruction and <child2>.
The xml can come like this too:
<root> <child1> child 1 </child1> <child2> child 2 </child2> </root> In this case it should return false
and like this:
<root> <?proc?> <child1> child 1 </child1> <child2> child 2 </child2> </root>
and here false too.
I tryed something like this
preceding-sibling::*[1]/name()|preceding-sibling()[1]/name = 'proc'
but it didn4t work.
Can anyone help me??
preceding-sibling::node()[not(self::text())][1]/
self::processing-instruction('proc')"Get the preceding sibling nodes of any kind, looking only at the non-text nodes, then looking only at the first of those, checking that node is a processing instruction with the name 'proc'."
T:\>type alexandre.xsl <?xml version="1.0" encoding="US-ASCII"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<xsl:for-each select="//child2">
<xsl:choose>
<xsl:when test="preceding-sibling::node()[not(self::text())][1]/
self::processing-instruction('proc')">Yes!</xsl:when>
<xsl:otherwise>No!</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:template></xsl:stylesheet>
T:\>type alexandre1.xml
<root>
<child1>
child 1
</child1>
<?proc?>
<child2>
child 2
</child2>
</root>T:\>xslt alexandre1.xml alexandre.xsl con
Yes!
T:\>type alexandre2.xml
<root>
<child1>
child 1
</child1>
<child2>
child 2
</child2>
</root>T:\>xslt alexandre2.xml alexandre.xsl con
No!
T:\>type alexandre3.xml
<root>
<?proc?>
<child1>
child 1
</child1>
<child2>
child 2
</child2>
</root>T:\>xslt alexandre3.xml alexandre.xsl con No! T:\>
-- Upcoming XSLT/XSL-FO, UBL and code list hands-on training classes: : Sydney, AU 2009-01/02; Brussels, BE 2009-03; Prague, CZ 2009-03 Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video Video sample lesson: http://www.youtube.com/watch?v=PrNjJCh7Ppg Video course overview: http://www.youtube.com/watch?v=VTiodiij6gE G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Male Cancer Awareness Nov'07 http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| RE: [xsl] Test processing instructi, Michael Kay | Thread | Re: [xsl] Test processing instructi, Florent Georges |
| [xsl] changing section of XML file, Furst, Tom | Date | RE: [xsl] changing section of XML f, Michael Kay |
| Month |