Hello,
I'm trying to perform some string manipulations in my stylesheet and
have gotten stuck on the issue below so hopefully can elicit some useful
hints.
Namely, the problem is that I need to convert an unqualified Xpath to
a fully qualified Xpath in an identity transform, i.e.
/AAA/BBB/CCC/@DDD
converted to
/ns:AAA/ns:BBB/ns:CCC/@DDD
with a predefined NS prefix and using a string tokenizer (adopted from
http://www.xslt.com/html/xsl-list/2005-04/msg00031.html) which returns
the tokens as:
<token>AAA</token>
<token>BBB</token>
<token>CCC</token>
<token>@DDD</token>
I'm assigning to the variable 'tokens' in the following template, which
then tries to produce the fully qualified namespace:
<xsl:template name="qualified Xpath">
<xsl:param name="unqualifi edXpath"/>
<!-- -->
<xsl:variable name="sampleUnq ualifiedXpath"
select="'/AAA/BBB/CCC/@DDD'"/>
<!-- hardcoded namespace prefix -->
<xsl:variable name="prefixStr ing" select="'dns:'"/>
<!-- hardcoded delimiter character -->
<xsl:variable name="slash" select="'/'"/>
<!-- Variable to contain the tokens -->
<xsl:variable name="tokens">
<!-- Calling tokenizer template-->
<xsl:call-template name="tokenizer ">
<xsl:with-param name="string" select="$sample UnqualifiedXpat h"/>
<xsl:with-param name="delimiter " select="$slash"/>
</xsl:call-template>
</xsl:variable>
<!-- Variable to hold the qualified Xpath -->
<xsl:variable name="qualXpath ">
<!-- Constructing the qualified Xpath-->
<!-- Iterate through the returned token nodes -->
<xsl:for-each select="$tokens/token">
<!-- Add delimiter-->
<xsl:value-of select="$slash"/>
<!-- Add prefix only when token is an element name i.e. doesn't have the
@ character -->
<xsl:if test="not(conta ins(.,'@'))">
<!-- Adding namespace prefix -->
<xsl:value-of select="$prefix String"/>
<!-- Add token's value -->
<xsl:value-of select="."/>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<!-- returning qualXpath variable -->
<xsl:value-of select="$qualXp ath"/>
</xsl:template>
where the tokens' usage in the loop declaration
<xsl:for-each select="$tokens/token">
is causing a Result Tree Fragment (RTF) error; I've googled to find out
more about it but frankly don't understand the problem, and unsure what
an alternative solution would be and hence seeking Wisdom of The Elders!
:-)
BTW, the code snippet above might be buggy (hopefully not too much) as
I've been stuck at this RTF error and hence unable to proceed. I suspect
the usage of contains(.,'@') ,
where I intend to check the token node's value for a '@' character, is
bit fishy. :)
Many thanks!
Regards,
Bilal B.
*** Sent via Developersdex http://www.developersdex.com ***