xsl-list
[Top] [All Lists]

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

2003-06-03 10:34:32
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[(_at_)role='dst'][(_at_)target=$b2/@id]][c1[(_at_)role='src'][(_at_)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



<Prev in Thread] Current Thread [Next in Thread>