[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
[xsl] template match : node-set paring through multiple-axis relationsh ips
Subject: [xsl] template match : node-set paring through multiple-axis relationsh ips From: Jonathan Sprinkle <jonathan.sprinkle@xxxxxxxxxxxxxx> Date: Thu, 29 May 2003 11:42:08 -0500 |
After about 4 hours of searching in the archives, I cannot find a similar problem. XSL-gurus: consider this problem your greatest nemesis, because as far as XSL is concerned, it certainly is mine. :) I want to know this: can I use the xpath expression of a template match to test id relationships at more than one point in the expression with the context of the matching node? For example... I want to match a node 'b' based on two relationships to another node 'b' in the file - relationship through containment and through association. I want to match this 'b' iff it is the source of an association AND the destination of that association is a child of my grandparent (the association, in my example, exists as IDREFs in a node neither an ancestor nor a descendent of the src/dst objects). The trouble comes that I can match if I am the source of this association, and that the destination is a 'b' node. AND I can match if my grandparent has a child that is a 'b' node, BUT I have no way of guaranteeing that those two 'b' nodes are identical. While this may seem like an insignificant problem, consider the template example, and the XML example that I have given below. If I cannot guarantee that the 'dst' and the "uncle" (for lack of a better term) are the same, then I will match <b id="_11"/> AND <b id="_12"/>, although <b id="_11"/> is the only node that I want. Currently my template example will match both <b id="_11"/> and <b id="_12"/> (at least, if I have stripped away all the space right!). Surely, someone out there has experience with this? It would work well if I could use the "current()" command, which is not permitted in a match-pattern. It is unacceptable to defer any testing to an "if" command inside the template, because failure in the "if" command leaves me no alternatives to match, and this 'b' node may require other processing if the match is not made. thanks is appreciated, Jon (examples below) ======== example of template ======== <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format"> <xsl:template match="/"> <xsl:apply-templates/> </xsl:template> <xsl:template match= "b [parent::a [parent::a [child::b] ] ] [@id= //c [id(c1[@role='dst']/@target)/self::b] /c1 [@role='src'] /@target ]" > <xsl:call-template name="WhatToDoWithMy_B_Now"/> </xsl:template> <xsl:template name="WhatToDoWithMy_B_Now"> <xsl:comment>Matched B...<xsl:value-of select="@id"/></xsl:comment> </xsl:template> </xsl:stylesheet> ======== example XML document ======== <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE root [ <!ELEMENT root ( a* | c* )*> <!ELEMENT a (a* | b*)*> <!ELEMENT b (#PCDATA)> <!ATTLIST b id ID #IMPLIED > <!ELEMENT c (c1*)> <!ELEMENT c1 (#PCDATA)> <!ATTLIST c1 role CDATA #IMPLIED target IDREF #IMPLIED > ]> <root> <a> <b id="_10"/> <a> <b id="_11"/> <b id="_12"/> </a> </a> <c> <c1 role="src" target="_11"/> <c1 role="dst" target="_10"/> </c> <c> <c1 role="src" target="_12"/> <c1 role="dst" target="_11"/> </c> </root> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] compiling in xsl, Jarno . Elovirta | Thread | [xsl] multiple input xml docs, Dave Dearman |
RE: [xsl] Axes, predicates, and fin, Erika Marlow | Date | RE: [xsl] Re: Flat -> Hierarchy ---, Dongling Ding |
Month |