EXSLT str:split() and evaluation context
Michael Ludwig <[email protected]> Sun, 23 Sep 2007 23:11:47 +0000
| Newsgroups | gmane.text.xml.xslt.extensions |
|---|---|
| Message-ID | <20070923231147.GC49280@wladimir> |
I have this document:
<?xml version="1.0" encoding="iso-8859-1"?>
<?xml-stylesheet type="text/xsl" href="exslt-str-split.xsl"?>
<ur txt="Blabla">
<bla nr="1">eins</bla>
<bla nr="2">zwei</bla>
<bla nr="3">drei</bla>
<bla nr="4">vier</bla>
</ur>
You can see these bla elements are numbered. Let's say, for the purpose
of this example, I want to pick just a few of them, using a number that
may come in as a parameter to my stylesheet.
Now I'm reading the EXSLT function str:split() takes a string and
returns a node set. Sounds like just what I need.
http://exslt.org/str/functions/split/
Maybe I can use it to produce a set of numbers I can use in a for-each
to iterate over a selection of bla elements. I could then pass a string
to my transformation that would translate to a node set suitable for
picking some elements. Unfortunately, that doesn't seem to work, neither
in xsltproc (based on libxslt by Daniel Veillard) nor in Xalan-J 2.7.
Here is my XSL.
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:str="http://exslt.org/strings"
extension-element-prefixes="str"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:variable name="blub" select="'Blubbel'"/>
<xsl:template match="ur">
<xsl:value-of select="/ur/bla[@nr = 1]"/>
<xsl:text> </xsl:text>
<xsl:for-each select="str:split('1 3')">
<!-- 1 --><xsl:value-of select="concat(local-name() , ' ')"/>
<!-- 2 --><xsl:value-of select="concat(. , ' ')"/>
<!-- 3 --><xsl:value-of select="/ur/bla[@nr = .]"/>
<!-- 4 --><xsl:value-of select="/ur/bla[@nr = 1]"/>
<!-- 5 --><xsl:value-of select="concat(. , '-', /ur/bla[@nr = .], ' ')"/>
<!-- 6 --><xsl:value-of select="concat(. , '-', /ur/@txt, ' ')"/>
<!-- 7 --><xsl:value-of select="concat(. , '-', $blub, ' ')"/>
<!-- --><xsl:text> </xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
What strikes me is line 3 through 7. In line 3 through 6 I'm
trying to reference the actual document in a for-each loop over
the node set returned by str:split() - but to no avail. The original
document seems inaccessible. On the other hand, the global variable
$blub referenced in line 7 is accessible. Here is the output by both
xsltproc and Xalan.
eins
token 1 1- 1- 1-Blubbel
token 3 3- 3- 3-Blubbel
The evaluation context seems to be stuck on the node set provided by
str:split() which is alien to the input document itself. Is this
assumption correct?
Is there any other way to access the original document in XSLT 1.0?
Maybe using the XSLT document() function?
Could anyone explain the rationale of all this? Why can I not access the
original document tree whereas I can access the global variable?
Is there any other way to use str:split() to produce a set of pointers
in order to perform a lookup on the original document?
Or is this an implementation issue xsltproc and Xalan happen to handle
the same way?
Any pointers welcome!
Michael