如何在xslt-1.0中使用SOH和ETX

发布于 2025-01-02 17:29:31 字数 2138 浏览 4 评论 0原文

如何使用 xslt -1.0 设置 SOH 和 ETX

我尝试了多种方法来达到输出,因为数字代码不接受此 xslt-1.0 并且这里编码是 utf-8。

如何在其中使用此十六进制代码...它不起作用,我需要做什么才能使其工作

SOH : 

ETX : &#03;< /code>

我也尝试过下面的一个来实现结果输出,但它不是..请大家建议一些事情...不,

<?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>

我已经在我的xslt中应用了上述逻辑,当我使用它时,它抛出错误:

XmlQueryRuntime {urn:schemas-microsoft-com:xslt-debug}运行时,XPathNavigator {urn:schemas-microsoft-com:xslt-debug}当前,双精度 {urn:schemas-microsoft-com:xslt-debug}位置, 双 {urn:schemas-microsoft-com:xslt-debug} 最后,IList`1 {urn:schemas-microsoft-com:xslt-debug}命名空间

和文件正在使用 0KB 创建,

<xsl:value-of select="char:toString(1)">

如果只是评论它工作正常......

这里是下面的 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>

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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

素罗衫 2025-01-09 17:29:31

我不确定你有什么例外,因为你所展示的内容似乎并不完整。 0x01 不是有效的 Xml 字符,这可能是异常的原因。我创建了一个稍微不同的样式表版本,如下所示:

<?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>

为了防止由于无效字符而失败,我需要在写入响应的编写器中禁用字符检查:

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));

导致以下输出的结果:

☺Press any key to continue . . .

如您所见字符被写入输出,没有任何异常。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文