Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 21st, 2007, 04:15 PM
Friend of Wrox
 
Join Date: May 2004
Posts: 109
Thanks: 18
Thanked 0 Times in 0 Posts
Default Document Order for preceding-sibling

Hi,

I've been given an XML file that I need to do some work on. I have very little control over the structure of the XML file (it was generated by Adobe FrameMaker).

The XML file uses Processing Instructions to flag certain aspects of the content (like marking it as conditional; it's a FrameMaker thing).

I'm trying to find the best way to find content that falls within a pair of Processing Instructions. Since they are not really start/end tag, I want to find a <? condstart ?> tag, then locate it's paired <? condend ?> tag and throw away everything in between.

To do this I need to know if preceding-sibling and following-sibling process nodes in document order, or reverse document order (for preceding-sibling).


------------------------
GnuPG Key fingerprint = 1AD4 726D E359 A31D 05BF&nbsp;&nbsp;ACE5 CA93 7AD5 D8E3 A876

Michael Hare
__________________
------------------------
Keep Moving Forward

GnuPG Key fingerprint = 1AD4 726D E359 A31D 05BF ACE5 CA93 7AD5 D8E3 A876

Michael Hare
 
Old February 21st, 2007, 04:29 PM
Friend of Wrox
 
Join Date: May 2004
Posts: 109
Thanks: 18
Thanked 0 Times in 0 Posts
Default

Well, I may be hosed. Once I find a PI, is it possible to parse the text within the PI?

I have <?Fm Condition AccessControlLists Teal%20(med) STRIKETHROUGH show?>, I detected it with <xsl:template match="processing-instruction()">. But can I parse the PI to find it's content? Specifically, is it 'STRIKETHROUGH', is it 'show'? What is the Type ('Condition')? What is the Name ('AccessControlList')

Are these detectable in XPATH/XSLT?




------------------------
GnuPG Key fingerprint = 1AD4 726D E359 A31D 05BF&nbsp;&nbsp;ACE5 CA93 7AD5 D8E3 A876

Michael Hare
 
Old February 21st, 2007, 06:03 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Instructions like xsl:for-each and xsl:apply-templates always process nodes in document order, regardless of the XPath expression that was used to locate the nodes. However, predicates like [1] consider the nodes in axis order, so preceding-sibling::*[1] is the immediately preceding sibling.

Parsing the content of your processing instructions will be much easier if you use XSLT 2.0, which gives you regular expression support. String manipulation can be done in XSLT 1.0, but it's a pain.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old February 21st, 2007, 07:05 PM
Friend of Wrox
 
Join Date: May 2004
Posts: 109
Thanks: 18
Thanked 0 Times in 0 Posts
Default

Thanks Michael.

I have both your XPATH 2.0 and XSLT 2.0 books. Looking through them, I'm missing how to access the resulting node text from the for-each or apply-template instruction.

------------------------
GnuPG Key fingerprint = 1AD4 726D E359 A31D 05BF&nbsp;&nbsp;ACE5 CA93 7AD5 D8E3 A876

Michael Hare
 
Old February 21st, 2007, 07:44 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You can capture the result in a variable:

<xsl:variable name="t">
  <xsl:apply-templates select-"...."/>
</xsl:variable>

and then process the variable, e.g.

<xsl:value-of select="count($t//xyz)"/>

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old February 22nd, 2007, 03:10 PM
Friend of Wrox
 
Join Date: May 2004
Posts: 109
Thanks: 18
Thanked 0 Times in 0 Posts
Default

Thanks again.
It looks like the regex in XPath 2 is going to be the way to do this.

------------------------
GnuPG Key fingerprint = 1AD4 726D E359 A31D 05BF ACE5 CA93 7AD5 D8E3 A876

Michael Hare





Similar Threads
Thread Thread Starter Forum Replies Last Post
Using preceding-sibling mcanne98 Infopath 0 September 11th, 2008 11:09 PM
traversing preceding-sibling in reverse doc order mphare XSLT 3 August 16th, 2007 01:28 PM
Preceding-sibling question. lafilip XSLT 7 March 5th, 2007 12:35 PM
preceding-sibling jonesyp XSLT 2 November 22nd, 2005 12:29 PM
preceding-sibling after sort rushman XSLT 3 January 18th, 2005 11:08 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.