简体   繁体   中英

XML fragment is not resolved correctly by msxsl:node-set()

I've got the following scenario.

<xsl:template match="/s0:NotChangableTemplate">
    <ns0:Root>
        <xsl:for-each select="s0:Element">
            <xsl:variable name="var" select="ext:MyCustomFunction(string(s0:Input/text()))" />

            <xsl:call-template name="MyTemplate">
                <xsl:with-param name="param" select="string($var)" />
            </xsl:call-template>
        </xsl:for-each>
    </ns0:Root>
</xsl:template>

<xsl:template name="MyTemplate">
    <xsl:param name="param" />

    <xsl:variable name="myVar">
        <xsl:value-of select="$param" disable-output-escaping="yes" />
    </xsl:variable>

    <xsl:for-each select="msxsl:node-set($myVar)/s0:Value">
        <xsl:copy-of select="self::node()" />
    </xsl:for-each>
</xsl:template>

The template /s0:NotChangableTemplate is generated code and I have no possibility to change this. The function MyCustomFunction returns ie the following XML fragment as string.

<s0:Value>'74024042','66111050','74024046','66110042','32060090'</s0:Value>
<s0:Value>'66111040','53260042','17439060','66111048','74024040'</s0:Value>
<s0:Value>'66110040','66110048','66110044','74024044','53283040'</s0:Value>
<s0:Value>'66111044','66111042','66111046','74024036','66110046'</s0:Value>
<s0:Value>'18235','17439058','53283038','53260036','66111038'</s0:Value>
<s0:Value>'74024038'</s0:Value>

In MyTemplate I want to resolve it to a tree and navigate through this. In this dummy function I simply want to copy the node into the output XML. But the s0:Value node is not found.

If I set the fragment fix in the variable it works.

<xsl:template name="MyTemplate">
    <xsl:variable name="myVar">
        <s0:Value>'74024042','66111050','74024046','66110042','32060090'</s0:Value>
        <s0:Value>'66111040','53260042','17439060','66111048','74024040'</s0:Value>
        <s0:Value>'66110040','66110048','66110044','74024044','53283040'</s0:Value>
        <s0:Value>'66111044','66111042','66111046','74024036','66110046'</s0:Value>
        <s0:Value>'18235','17439058','53283038','53260036','66111038'</s0:Value>
        <s0:Value>'74024038'</s0:Value>
    </xsl:variable>

    <xsl:for-each select="msxsl:node-set($myVar)/s0:Value">
        <xsl:copy-of select="self::node()" />
    </xsl:for-each>
</xsl:template>

What can I change in MyTemplate that it will also works like in the example with the fix variable value?

Thanks in advance.

Documentation for msxsl:node-set() can be found here:

Support for the msxsl:node-set() Function

There is no suggestion in the documentation that it will parse a string containing lexical XML to produce a tree of nodes; I'm not sure where you got that idea from.

XSLT 1.0 provides no mechanism to invoke an XML parser (XSLT 3.0 offers the parse-xml() function). But msxsl allows you to call out to Javascript for such things.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM