Skip to content

Instantly share code, notes, and snippets.

@steppat
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steppat/3da868e9ca88893b692a to your computer and use it in GitHub Desktop.
Save steppat/3da868e9ca88893b692a to your computer and use it in GitHub Desktop.
Template para adicionar cabeçalho na mensgagem SOAP
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
version="1.0">
<xsl:output method="xml" indent="yes"/>
<!-- o template abaixo copia o XML inteiro -->
<!-- @* - seleciona todos os atributos -->
<!-- node() - seleciona todos os nodes -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<!-- o template abaixo adiciona um Header e o elemento tokenUsuario se nao existe o Header ainda -->
<xsl:template match="*:Envelope[not(*:Header)]">
<xsl:copy>
<soapenv:Header >
<aut:tokenUsuario xmlns:aut="http://caelum.com.br/autorizacao">TOKEN123</aut:tokenUsuario>
</soapenv:Header>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
<!-- o template abaixo adiciona o elemento tokenUsuario se o Header já existe -->
<xsl:template match="*:Header">
<xsl:copy>
<!-- adicione elemento abaixo ao header -->
<aut:tokenUsuario xmlns:aut="http://caelum.com.br/autorizacao">TOKEN123</aut:tokenUsuario>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment