I finally figured out how to do something that's been bugging me for
ages.
I wanted to have two input documents, one is RNG and it defines the
structure of a document. The other one is an instance document. I want
to determine a path from the RNG (relax NG) and see if there's an
instance value for it in the instance document.
<xsl:template name="InstanceValue">
<xsl:variable name="instPathStr">
<xsl:for-each select="current()/ancestor-or-self::*[(_at_)name]">
<xsl:text>/</xsl:text>
<xsl:value-of select="@name"/>
</xsl:for-each>
</xsl:variable>
<xsl:for-each select="document('inst.xml')">
<xsl:if test="not(dyn:evaluate($instPathStr)/*)">
<prefilled-path><xsl:value-of
select="$instPathStr"/></prefilled-path>
<prefilled-value>
<xsl:value-of select="dyn:evaluate($instPathStr)"/>
</prefilled-value>
</xsl:if>
</xsl:for-each>
</xsl:template>
I make use of several non-obvious things in this (IMHO!) although maybe
it could be improved further. First, I used a for-each
select=document('inst.xml') because you're not allowed to do ... well,
I had the document in a variable actually and you can't do
$variable/$var2 ... grr! Also, you'll note that instPathStr gets
created as a string and then I use dyn:evaluate to turn it back into a
node set inside the document context! That's because if I made a
node-set in the variable it would implicitly be in the source document
(the RNG) instead of in the inst.xml (right?!)
I'd love to know if there's any better ways to do this ... but it works
:-D
simon
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list