|
Subject: Selection of an XML-Tree will not work From: Conny Kreyßel <Conny.Kreyssel@xxxxxxxxxxxxxx> Date: Mon, 31 Jul 2000 09:49:20 +0200 |
Hi,
I have confused Problem with XPath.
Im trying to create a XPath statement to select a subsection of an XML-Tree.
Please let me you give first a example of the tree.
<tree>
<entry id="1">
<entry id="A">
<entry/>
<entry id="2">
<entry id="B">
<entry id="I"/>
<entry/>
<entry id="C">
<entry id="J"/>
<entry/>
<entry/>
<entry id="3">
<entry id="D">
<entry/>
</tree>
Ok fine - thats the tree. And now let me describe how I would select the
tree.
My wish is it - I would say give me all ancestor and from one of the
anscestors element all childs. I give you now a little example.
When I say select me the Tree for ID="I" it should me select the following
tree.
<tree>
<entry id="1"/>
<entry id="2">
<entry id="B">
<entry id="I"/>
<entry/>
<entry id="C"/>
<entry/>
<entry id="3"/>
</tree>
You see - it selects all elements from depth=1, but no subelement from
id="1" and id="3", and in depth=2, only subelements from id="B", but no
subelements from id="C".
Ok this is what I want - and I have also a code that worked, here is the
code example:
<xsl:template match="tree">
<xsl:for-each select="//*">
<xsl:if test="$navid=string(@id)">
<xsl:if test="boolean(@title)">
<xsl:variable name="subid">
<xsl:number level="multiple" format="A."/>
</xsl:variable>
<xsl:for-each select="//*">
<xsl:variable name="curid">
<xsl:number level="multiple" format="A."/>
</xsl:variable>
<xsl:variable name="curid">
<xsl:value-of
select="substring($curid,0,string-length($curid)-1)"/>
</xsl:variable>
<xsl:if test="starts-with($subid,$curid)">
<xsl:value-of select="@id"/><br/>
</xsl:if>
</xsl:for-each>
</xsl:if>
</xsl:if>
</xsl:for-each>
</xsl:template>
$navid is a variable who is set the ID what should selected.
This code worked fine but I hope you can tell me how I can select the same
Path with XPath.
- Conny -
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: HTML in XML?, Norman Walsh | Thread | RE: Selection of an XML-Tree will n, Kay Michael |
| Re: HTML in XML?, Paul Tchistopolskii | Date | xsl attributes - include and import, Tamsin |
| Month |