Reputation: 396
I am trying to map the input XML to variable but it is eliminating all the tag's name passing only the value of the tag.
Input XML
<Response>
<FirstName>Manoj</FirstName>
<LastName>Naik</LastName>
</Response>
XSLT
<xsl:stylesheet version="3.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
exclude-result-prefixes="xsl in lang user f msxsl"
xmlns:in="http://www.composite.net/ns/transformation/input/1.0"
xmlns:lang="http://www.composite.net/ns/localization/1.0"
xmlns:f="http://www.composite.net/ns/function/1.0"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:user="urn:my-scripts">
<msxsl:script language="C#" implements-prefix="user">
<msxsl:assembly name="System.Data"/>
<![CDATA[
public string GetVaribaleData(string text)
{
return text;
}
]]>
</msxsl:script>
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />
<xsl:template match="/">
<xsl:variable name="encdata">
<xsl:copy-of select="." />
<!--<xsl:copy-of select="node()"/>-->
<!--<xsl:copy-of select="*" />-->
<!-- <xsl:copy-of select="node()|@*" /> -->
</xsl:variable>
<xsl:variable name="json" select="user:GetVaribaleData($encdata)"/>
</xsl:template>
</xsl:stylesheet>
With the above code in the output variable it is returning \n\tManoj\n\tNaik\n
Expected information in the variable encdata
and parameter present in C# function text
as below -
<Response>
<FirstName>Manoj</FirstName>
<LastName>Naik</LastName>
</Response>
I want to pass the Input XML along with element name to encdata
present in the XSLT. I want to use that variable in C# code to do further processing on the same.
Is there any way to do the same?
Upvotes: 0
Views: 1249
Reputation: 70648
This was too long to write in comments, but do you really need to use a C# function there, which will tie your code to a specific processor? Perhaps you can achieve the same in pure XSLT, using a named template?
For example, try this XSLT:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:in="http://www.composite.net/ns/transformation/input/1.0"
xmlns:lang="http://www.composite.net/ns/localization/1.0"
xmlns:f="http://www.composite.net/ns/function/1.0"
exclude-result-prefixes="in lang f">
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />
<xsl:template name="GetVariableData">
<xsl:param name="node" />
<xsl:param name="name" />
<xsl:value-of select="$node/*[local-name() = $name]" />
</xsl:template>
<xsl:template match="/">
<xsl:variable name="encdata" select="Response" />
<xsl:call-template name="GetVariableData">
<xsl:with-param name="node" select="$encdata" />
<xsl:with-param name="name" select="'LastName'" />
</xsl:call-template>
</xsl:template>
</xsl:stylesheet>
Upvotes: 0