Subject: [xsl] traversing the tree from an arbitrary node From: "Chris d'Aquin" <CDAquin@xxxxxxxxxxx> Date: Wed, 15 Aug 2001 10:55:23 -0500 |
I am trying to traverse the tree from an arbitrary node (as designated by its ID). But I can't get it right! As some background, I have an XML document where if I find a certain tag with a certain attribute I need to check the previous and/or following identical tag to see if it is nested at the same depth within the document. If not, there is a basic structural error within the file that needs to be corrected before the XML file can be fully processed. Here is some sample XML: <rootTag> <parentTag> <childTag id='id1' att='checkThis'> . . . some info . . . </childTag> </parentTag> <parentTag> <childTag id='id2' att='thisChecks'> . . . some more info . . . </childTag> </parentTag> </rootTag> When I find a <childTag>, I count how deep the tag is from <rootTag>, get the ID of the next <childTag>, then try to see if the next <childTag> is at the same depth. Here are the steps from the stylesheet: <xsl:if test="@att='checkThis'"> <xsl:variable name="elementDepth"> <xsl:value-of select="count(ancestor::*)" /> <!-- this gets the depth of the current childTag from rootTag, right? --> </xsl:variable> <xsl:variable name="id"> <xsl:value-of select="following::childTag[1]/@id" /> </xsl:variable> <xsl:choose> <xsl:when test="id('$id')/from-ancestors(*[position() =$elementDepth][self::rootTag])"> <!-- do nothing since this is the right depth --> </xsl:when> <xsl:otherwise> . . . error message . . . </xsl:otherwise> </xsl:choose> </xsl:if> I am using XT on a Windows NT platform. When I run this, I get the error message of "expected node test" for the line that has the id() function. What I am trying to say for that node test is "from the node that has this id, go up $elementDepth ancestor nodes and see if that node is <rootTag>." What am I doing wrong? Thanks, Chris +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Chris d'Aquin, XML Engineer Questia Media, Inc. 713.358.2515 cdaquin@xxxxxxxxxxx http://www.questia.com/ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Extensions and namespace , Jeni Tennison | Thread | Re: [xsl] traversing the tree from , cutlass |
Re: [xsl] Re: Microsoft XML, Kurt Cagle | Date | Re: [xsl] traversing the tree from , cutlass |
Month |