我想替换>;与&;燃气轮机;对于使用xslt的xml中的某些节点

我想替换>;与&;燃气轮机;对于使用xslt的xml中的某些节点,xml,xpath,xslt-1.0,Xml,Xpath,Xslt 1.0,我需要在wihch中为一些节点输出soap xml请求应替换为 如何使用xslt实现这一点 我的输出应该如下所示 <env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <env:Body><Create xmlns="http://jerseytelecom.com/"> <

我需要在wihch中为一些节点输出soap xml请求
应替换为
如何使用xslt实现这一点 我的输出应该如下所示

<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"     xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<env:Body><Create xmlns="http://jerseytelecom.com/">
<requestXml>
&lt;ISD_XMLGateway&gt;
&lt;Entity&gt;HLR_ALC&lt;/Entity&gt;
&lt;Origin&gt;Comverse One&lt;/Origin&gt;
&lt;Log_Level&gt;0&lt;/Log_Level&gt;
&lt;Params&gt;&lt;Param Name=&quot;HLR_System&quot; Value=&quot;JT&quot;/&gt;
&lt;Param Name=&quot;HLR_ALC_Command&quot; Value=&quot;Send_HLR_Command&quot;/&gt;
&lt;Param Name=&quot;HLR_Command&quot; Value=&quot;CRESBX:MSIN=112210231,MODEL=MODEL001,SNBSV=7797242727-TEL;&quot;/&gt;
&lt;/Params&gt;
&lt;/ISD_XMLGateway&gt;
</requestXml></Create></env:Body></env:Envelope>

综合业务数字网关
实体HLR\U ALC/实体
原文一/原文
日志级别0/日志级别
ParamsParam Name=“HLR\U系统”Value=“JT”/
Param Name=“HLR\U ALC\U命令”Value=“发送HLR\U命令”/
Param Name=“HLR_Command”Value=“CRESBX:MSIN=112210231,MODEL=MODEL001,SNBSV=7797242727-TEL;”/
/Params
/综合业务数字网关

嗯,XSLT永远看不到XML标记中的“”字符,因为它不适用于词法XML,而是适用于XML的树表示形式。所以你对这个问题的表述是错误的。实际上,您要做的是将树序列化为词法XML,然后将该词法XML作为字符串插入到结果树中(接下来,序列化程序将该词法XML中的“”字符转换为“<;”和“>;”)


XSLT 2.0中没有内置的serialize()函数来实现这一点,但最近的Saxon版本(仅限商业版)支持XSLT 3.0 serialize()函数。

我认为这应该可以在XSLT 1.0中转义XML:

  <xsl:template match="*" mode="escape">
    <xsl:variable name="currentNode" select="." />
    <xsl:value-of select="concat('&lt;', name(.))"/>
    <xsl:apply-templates select="@*" mode="escape"/>
    <xsl:for-each select="namespace::*[name() != 'xml'][not(. = $currentNode/../namespace::*)]">
      <xsl:call-template name="EscapeNamespace">
        <xsl:with-param name="namespace" select="." />
      </xsl:call-template>
    </xsl:for-each>
    <xsl:value-of select="'&gt;'"/>
    <xsl:apply-templates select="node()" mode="escape" />
    <xsl:value-of select="concat('&lt;/', local-name(.), '&gt;')"/>
  </xsl:template>

  <xsl:template match="@*" mode="escape">
    <xsl:value-of select="concat(' ', name(.), '=&quot;')"/>
    <xsl:call-template name="EscapeText">
      <xsl:with-param name="text" select="." />
    </xsl:call-template>
    <xsl:value-of select="'&quot;'"/>
  </xsl:template>

  <xsl:template match="text()" mode="escape">
    <xsl:call-template name="EscapeText">
      <xsl:with-param name="text" select="." />
    </xsl:call-template>
  </xsl:template>

  <xsl:template name="EscapeNamespace">
    <xsl:param name="namespace" />

    <xsl:variable name="prefix">
      <xsl:choose>
        <xsl:when test="name($namespace) = ''">
          <xsl:value-of select="'xmlns'"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="concat('xmlns:',name($namespace))" />
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>

    <xsl:value-of select="concat(' ', $prefix, '=&quot;')"/>
    <xsl:call-template name="EscapeText">
      <xsl:with-param name="text" select="$namespace" />
    </xsl:call-template>
    <xsl:value-of select="'&quot;'"/>
  </xsl:template>

  <xsl:variable name="EntitiesRaw">
    <entity value="&quot;" escaped="&amp;quot;" />
    <entity value="&amp;" escaped="&amp;amp;" />
    <entity value="&lt;" escaped="&amp;lt;" />
    <entity value="&gt;" escaped="&amp;gt;" />
    <entity value="&apos;" escaped="&amp;apos;" />
  </xsl:variable>
  <xsl:variable name="Entities" select="msxsl:node-set($EntitiesRaw)" />

  <xsl:template name="EscapeText">
    <xsl:param name="text" />

    <xsl:variable name="foundEntity" select="$Entities/entity[contains($text, @value)]" />
    <xsl:choose>
      <xsl:when test="$foundEntity">
        <xsl:call-template name="EscapeText">
          <xsl:with-param name="text" select="substring-before($text, $foundEntity/@value)" />
        </xsl:call-template>
        <xsl:value-of select="$foundEntity/@escaped" />
        <xsl:call-template name="EscapeText">
          <xsl:with-param name="text" select="substring-after($text, $foundEntity/@value)" />
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$text"/>
      </xsl:otherwise>
    </xsl:choose>

  </xsl:template>


它是否总是在
标记中包含值?您使用哪个XSLT2.0处理器?要转换为显示的结果的示例输入看起来如何?有些处理器(如Saxon 9)具有扩展函数(如yes),这些函数的值将始终在内部。感谢您的帮助,我们已设计为以以下格式发送xml
  <xsl:template match="something">
    <requestXml>
    <xsl:variable name="requestXml">
      <ISD_XMLGateway>
        <Entity><xsl:value-of select="2 + 5" /></Entity>
        <Origin>5 &lt; 6 and 7 > 2</Origin>
        <xsl:apply-templates select="otherStuff" />
        <ElementWithAttributes a="10" b="12" />
      </ISD_XMLGateway>
    </xsl:variable>

    <xsl:apply-templates select="msxsl:node-set($requestXml)" mode="escape" />
    </requestXml>
  </xsl:template>