B
Bilal
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="qualifiedXpath">
<xslaram name="unqualifiedXpath"/>
<!-- -->
<xsl:variable name="sampleUnqualifiedXpath"
select="'/AAA/BBB/CCC/@DDD'"/>
<!-- hardcoded namespace prefix -->
<xsl:variable name="prefixString" 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="$sampleUnqualifiedXpath"/>
<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(contains(.,'@'))">
<!-- Adding namespace prefix -->
<xsl:value-of select="$prefixString"/>
<!-- Add token's value -->
<xsl:value-of select="."/>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<!-- returning qualXpath variable -->
<xsl:value-of select="$qualXpath"/>
</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.
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="qualifiedXpath">
<xslaram name="unqualifiedXpath"/>
<!-- -->
<xsl:variable name="sampleUnqualifiedXpath"
select="'/AAA/BBB/CCC/@DDD'"/>
<!-- hardcoded namespace prefix -->
<xsl:variable name="prefixString" 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="$sampleUnqualifiedXpath"/>
<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(contains(.,'@'))">
<!-- Adding namespace prefix -->
<xsl:value-of select="$prefixString"/>
<!-- Add token's value -->
<xsl:value-of select="."/>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<!-- returning qualXpath variable -->
<xsl:value-of select="$qualXpath"/>
</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.