how to use SOH and ETX in xslt-1.0
-
17-05-2021 - |
Question
how to set SOH and ETX by using xslt -1.0
I have tried numerous ways i dint reached output, since numeric code are not accepting this xslt-1.0 and here encoding is utf-8.
how to use this hexadecimal code in it ...it was not working what do i need to do for make it work
SOH : 
ETX : 
I have tried this below one also for to achieve the resultant output but it was not ..guys kindly suggest some thing...nah
<?xml version="1.0" encoding="US-ASCII" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:char="java.lang.Character" version="1.0">
<xsl:output method="text" encoding="US-ASCII" />
<xsl:template match="/">
<xsl:value-of select="char:toString(1)"></xsl:value-of>
</xsl:template>
</xsl:stylesheet>
I have applied the above logic in my xslt when i use this it was throwing error :
XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}runtime, XPathNavigator {urn:schemas-microsoft-com:xslt-debug}current, Double {urn:schemas-microsoft-com:xslt-debug}position, Double {urn:schemas-microsoft-com:xslt-debug}last, IList`1 {urn:schemas-microsoft-com:xslt-debug}namespaces
and file was creating with 0KB
<xsl:value-of select="char:toString(1)">
if just comment on that it was working fine...
here is below xslt
<?xml version="1.0" encoding="us-ascii"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:char="java.lang.Character" version="1.0" >
<xsl:output method="text" indent="no" omit-xml-declaration ="yes" encoding="us-ascii"/>
<xsl:param name="PackageId" />
<xsl:param name="SequenceNum" />
<xsl:template match="/">
<xsl:value-of select="char:toString(1)"></xsl:value-of>
<xsl:apply-templates mode="block1" select="NewDataSet/Table1[CTC_PACKAGE_ID =$PackageId][position()=1]"/>
<xsl:apply-templates mode="block2" select="NewDataSet/Table[CTD_CTD_PKG_ID =$PackageId][CTD_SEQ_NUM =$SequenceNum]"/>
</xsl:template>
<xsl:template mode="block1" match="Table1">
...some code....
</xsl:template>
<xsl:template mode="block2" match="Table">
...some code....
</xsl:template>
Solution
I am not sure what exception you had since what you showed does not seem to be complete. 0x01 is not a valid Xml character and this might be the reason for the exception. I created a slightly different version of your stylesheet that looks like this:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl" xmlns:myScripts="myScripts">
<xsl:output method="text" indent="yes"/>
<msxsl:script implements-prefix="myScripts" language="C#">
public string SOH()
{
return '\u0001'.ToString();
}
</msxsl:script>
<xsl:template match="/">
<xsl:value-of select="myScripts:SOH()"></xsl:value-of>
</xsl:template>
</xsl:stylesheet>
To prevent it from failing due to the invalid character I needed to disable character checking in the writer that writes the response:
var xslt = new XslCompiledTransform();
xslt.Load(@"C:\Temp\xsl.xsl", new XsltSettings() { EnableScript = true }, null);
var xml = new XPathDocument(new StringReader("<root/>"));
var writerSettigns = xslt.OutputSettings.Clone();
writerSettigns.CheckCharacters = false;
xslt.Transform(xml, XmlWriter.Create(Console.Out, writerSettigns));
what resulted in the following output:
☺Press any key to continue . . .
As you can see the character was written to the output without and there was no exception.