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

Posted by Guillaume on Stack Overflow See other posts from Stack Overflow or by Guillaume
Published on 2010-03-30T10:27:45Z Indexed on 2010/03/31 3:33 UTC
Read the original article Hit count: 326

Filed under:

I have an XML file which has many section like the one below:

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

I have to add an <Action/> to every <Operations/>. It seems that an XSLT should 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 the content of my <Action/> contains some xPath expressions. For example:

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

The ${gel_stepInstanceId} is interpreted by my XSLT but I would like it to be copied as-is. Is that possible? How?

© Stack Overflow or respective owner

Related posts about xslt