Project

Profile

Help

Trying to return XML string value in stylesheet parameter but result is encoded. - .NET 10.6

Added by Matt Van Voorhies almost 2 years ago

Hey folks, I was hoping someone might help me. We have a .NET project where we replaced another XML processing engine/package with Saxon 10.6. In the previous processing (using the old library), we were able to take stylesheet parameters and apply chunks of XML - essentially injecting XML via the stylesheet parameters.

When I try to do this with Saxon, I get the content, but it's encoded. For example: <article-title> <p>test 15763 testweb2</p> </article-title>

The XSL that forms this is:

<xsl:template match="article-meta/title-group/article-title">
    <xsl:copy-of select="$VariableName"/>
</xsl:template>

And I've tried a number of ways to get that to render, but to no avail. We also specify a bunch of other parameters, but just as plain values that work fine. The c# code as it is today is:

parameters.Add(new QName("", "VariableName"), new XdmAtomicValue(MethodThatReturnsXMLStringThatCannotBeChangedToNotReturnXML));

I suspect that this is intentional (in other words, this is a security feature rather than a bug) and there isn't really a comparable way to do this kind of XML "injection". It is important to be minimally disruptive and I can't adjust the method to return a plain text string. So is there a way to do this easily that I'm just missing, or if not - what would be the recommended way to achieve the same result??


Replies (3)

Please register to reply

RE: Trying to return XML string value in stylesheet parameter but result is encoded. - .NET 10.6 - Added by Martin Honnen almost 2 years ago

XSLT 3 0 has a function parse-xml-fragment you could call on the variable reference.

RE: Trying to return XML string value in stylesheet parameter but result is encoded. - .NET 10.6 - Added by Michael Kay almost 2 years ago

At some stage the lexical XML has to be parsed into a node tree. You can either do this in the C# code (by invoking DocumentBuilder.Build()), or you can do it in the XSLT code (by calling the fn:parse-xml() function).

Alternatively you could copy the lexical XML, without parsing, directly into the serialized output, by using <xsl:value-of select="$VariableName" disable-output-escaping="yes"/>. But I wouldn't recommend that because it makes your code less reusable - it means the transformation and the serializer are very closely coupled.

RE: Trying to return XML string value in stylesheet parameter but result is encoded. - .NET 10.6 - Added by Matt Van Voorhies almost 2 years ago

Thanks guys! We truly appreciate the fantastic support you both provide! I'll take this back to our Product/XML guys and may come back for additional follow-ups on this after we get a chance to evaluate.

    (1-3/3)

    Please register to reply