2

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>

mzjn
  • 48,958
  • 13
  • 128
  • 248
shannu
  • 187
  • 1
  • 2
  • 11
  • @Dimitre Novatchev i hope you know the ans for the above, kindly help to sort out this, here i m using version 1.0 and encoding utf-8 i cant able to use "" in xslt file. – shannu Feb 07 '12 at 05:31
  • +1 For knowing who will probably answer this question :) – Ates Goral Feb 07 '12 at 05:39
  • @Ates Goral i have seen one of the site he was deal with SOH, but it was not clear on that, thats why i have said like that :), any way have to know any idea of about that ,if you so please suggest me – shannu Feb 07 '12 at 05:43
  • @Stephen Denne can you please help me on this for to achieve this soh and etx – shannu Feb 07 '12 at 16:14

1 Answers1

1

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.

Pawel
  • 31,342
  • 4
  • 73
  • 104
  • thanks a lot for replying,i have tried with your input then i have recieved this error: Cannot find a matching 0-argument function named {myScripts}SOH() – shannu Feb 07 '12 at 18:58
  • Weird. Are you using XslCompiledTransform? Can you show the full stack trace? I copied this from a working solution. – Pawel Feb 07 '12 at 19:16
  • for making myscripts enable true we need to assign XslCompiledTransform transform = new XslCompiledTransform(true); transform.Load(strCID, new XsltSettings() { EnableScript = true }, null); is it okay ? still do i need to do any modifications in transform.transform(sampleCID.xml,xmlarglist,sw); – shannu Feb 07 '12 at 19:33
  • Yes. You need to create your own writer and set the writeSettings.CheckCharacters to false. Otherwise the writer will throw when it encounters 0x01 value since it is not a valid Xml character. You need to clone form xslt to not lose settings. Here is more or less how it should look like: var writerSettigns = transform.OutputSettings.Clone(); writerSettigns.CheckCharacters = false; using (XmlWriter writer = XmlWriter.Create(strFileName, writerSettigns)) { transform.Transform("sampleCID.xml", xmlArgsList, writer); } – Pawel Feb 07 '12 at 20:44
  • Even though you provide StreamWriter the XslCompiledTransform class will create an XmlWriter instance to be able to serialize transformation results. The "problem" is that the XmlWriter created by the XslCompiledTransform always checks character and will not allow wrtiting 0x01. Therefore you need to do what XslCompiledTransform does but you also need to disable character checking. Cloning the settings will ensure that what you put in isnstruction will not get lost. – Pawel Feb 08 '12 at 06:15
  • if have followed your step it works great,but when i see the message in hexa edit format before 01 some junk is coming Reference No, before reference num 01 is correct but before than that some junk data was coming – shannu Feb 08 '12 at 07:17
  • public string ETX() { return '\u0003'.ToString(); } i have added ETX it was working fine, but soh only it was coming like as space in text document when we check in hexa edit format junk was coming before 01 so it was not replicating properly – shannu Feb 08 '12 at 08:10
  • dear pawel, if i use your input code for generating SOH and ETX, then it was generating ETX properly but when coming SOH i could not see in the file , but when the file content if i would see in hexadecimal format it was showing as 01 but it was generating as a space in the file it was not showing properly ? can you please guide me on this please – shannu Feb 08 '12 at 12:58
  • The "junk" you are seeing are probably BOM characters (especially if you are seeing something like "" (EF BB BF) or "þÿ" FE FF). See this for more details on BOM - http://en.wikipedia.org/wiki/Byte_order_mark. I think you can tell the StreamWritert to not write BOM characters (see: http://stackoverflow.com/questions/2437666/write-text-files-without-byte-order-mark-bom). – Pawel Feb 08 '12 at 21:58
  • i have done it, now the BOM characters are not coming,problem with SOH only it was looks like a space in text document, when if you see the same file hexadecimal format it was showing as 01, when coming ETX , i can see the value directly in text document as small l ,normally soh looks in text document as small r – shannu Feb 09 '12 at 02:41
  • I don't think you can/should use a text editor to view binary files. Each editor may have its own way of displaying characters binary/control characters. – Pawel Feb 09 '12 at 17:50
  • yeah okay but, it was not showing any display value, it was showing like space – shannu Feb 09 '12 at 19:08