RE: [xsl] template match : node-set paring through multiple-axis relationships

Subject: RE: [xsl] template match : node-set paring through multiple-axis relationships
From: Jonathan Sprinkle <jonathan.sprinkle@xxxxxxxxxxxxxx>
Date: Tue, 3 Jun 2003 12:34:32 -0500
>From message
(http://www.biglist.com/lists/xsl-list/archives/200305/msg01198.html)

Discouraged by XSL's limitations, I gave up doing it the nice way and hacked
my own solution.  In case you care, here it is.  It is a pain in the bum,
because now I have to create a bunch of variables, and do my own name
mangling if I have two different things to do to a 'b' in two different
contexts because XSL's namespace is intuitively different from conventional
namespaces in C++.  However, it works, and I can generate it generically
from a graphical transformation language.

For those who are in charge, and using this list to educate others on XSL to
evangelise it to the world on XSL and its usage, I am disappointed that no
one responded to my request, even to say "boy, that sure is a different
problem".  :(

Jonathan

=========== XSL Stylesheet ==========
<?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">
                <xsl:variable name="focus" select="current()"/>
                <xsl:variable name="b2"
select="parent::a/parent::a/child::b" />
                <xsl:choose>
                        <xsl:when test="current(
)[$b2][$focus][//c[c1[@role='dst'][@target=$b2/@id]][c1[@role='src'][@target
=$focus/@id]]]">
                                <xsl:call-template
name="WhatToDoWithMy_B_Now"/>
                        </xsl:when>
                </xsl:choose>
        </xsl:template>
        <xsl:template name="WhatToDoWithMy_B_Now">
                <xsl:comment>Matched B...<xsl:value-of select="@id"/>
                </xsl:comment>
        </xsl:template>
</xsl:stylesheet> 

=========== XML Source ==========
<?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