How to add a complex structure to multiple places in an XML file

I have an XML file that has many sections, as shown below:

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

I need to add <Action/>to each <Operations/>. XSLT seems to be a good solution to this problem:

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

My problem is that my content <Action/>contains some xPath expressions. For instance:

<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}interpreted by my XSLT, but I would like it to be copied as-is. Is it possible? How?

+3
source share
3 answers

I found that I can use:

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

It’s easier for me than replacing all instances of $ {} ...

, XSLT XMLSpy, , "disable-output-escaping" ... ...

+1

XSLT 1.0 ( 2.0) , / AVT.

:

, .

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

, :

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

- " " (AVT). XSLT , - AVT .

0
source

Source: https://habr.com/ru/post/1739129/


All Articles