代码之家  ›  专栏  ›  技术社区  ›  Guillaume

如何在XML文件的多个位置添加一些复杂的结构

  •  3
  • Guillaume  · 技术社区  · 16 年前

    我有一个XML文件,它有许多类似下面的部分:

    <Operations>
      <Action [some attributes ...]>
        [some complex content ...]
      </Action>
      <Action [some attributes ...]>
        [some complex content ...]
      </Action>
    </Operations>
    

    我得加一个 <Action/> 每一个 <Operations/>

    <xsl:template match="Operations/Action[last()]">
      <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
      </xsl:copy>
      <Action>[some complex content ...]</Action>
    </xsl:template>
    
    <xsl:template match="@*|node()">
      <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
      </xsl:copy>
    </xsl:template>
    

    我的问题是 <行动/> 包含一些xPath表达式。例如:

    <Action code="p_histo01">
      <customScript languageCode="gel">
        <gel:script
              xmlns:core="jelly:core"
              xmlns:gel="jelly:com.niku.union.gel.GELTagLibrary"
              xmlns:soap="jelly:com.niku.union.gel.SOAPTagLibrary"
              xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/"
              xmlns:sql="jelly:sql"
              xmlns:x="jelly:xml"
              xmlns:xog="http://www.niku.com/xog"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
          <sql:param value="${gel_stepInstanceId}"/>
        </gel:script>
      </customScript>
    </Action>
    

    这个 ${gel_stepInstanceId} 是由我的XSLT解释的,但我希望它被原样复制。有可能吗?怎么用?

    3 回复  |  直到 16 年前
        1
  •  4
  •   Dimitre Novatchev    16 年前

    The XSLT 1.0 (and also 2.0) spec defines a strict way to escape curly braces 属性值内部 ,因此它们不用于表示AVT的开始/结束。

    引用规范:

    表达式外的花括号将

    使用 :

      <sql:param value="${{gel_stepInstanceId}}"/>
    
        2
  •  1
  •   Guillaume    16 年前

    我发现我可以使用:

    <xsl:text disable-output-escaping="yes">
      <[CDATA[
        <Action>[...]</Action>
      ]]>
    </xsl:text>
    

    对我来说,替换${}的所有实例要容易得多。。。

        3
  •  0
  •   Tomalak    16 年前

    当然,这很简单:

    <sql:param value="{'${gel_stepInstanceId}'}"/>
    

    实际的 AVT,并将一个字符串值传递给它以显示。