2017-02-01 16 views
-2

xslファイルからいくつかのパラメータを受け取り、出力に見られるように追加する必要があるタグを返す必要があります。入力メッセージxslファイルから別のファイルへの呼び出しと応答の受信

入力

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://ejemplo.com/servicios"> 
    <soapenv:Header/> 
    <soapenv:Body> 
     <ser:Consultar> 
     <headerIn> 
      <dispositivo>01010101010101010101010101010101</dispositivo> 
      <medio>010001</medio> 
      <aplicacion>00006</aplicacion> 
     </headerIn> 
     <bodyIn> 
      <field1>1790197948001</field1> 
      <field2>0003</field12> 
     </bodyIn> 
     </ser:Consultar> 
    </soapenv:Body> 
</soapenv:Envelope> 

と私は、このXSLコードをしようとしている

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://ejemplo.com/servicios"> 
    <soapenv:Header/> 
    <soapenv:Body> 
     <ser:Consultar> 
     <headerIn> 
      <dispositivo>01010101010101010101010101010101</dispositivo> 
      <medio>010001</medio> 
      <aplicacion>00006</aplicacion> 
      <poli> 
       <teller>1</teller> 
       <terminal>3</terminal> 
      </poli> 
     </headerIn> 
     <bodyIn> 
      <field1>1790197948001</field1> 
      <field2>0003</field12> 
     </bodyIn> 
     </ser:Consultar> 
    </soapenv:Body> 
</soapenv:Envelope> 

この出力を必要とする

<xsl:stylesheet version="1.0" extension-element-prefixes="dp" exclude-result-prefixes="dp" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tns="http://www.example.org/tns" xmlns:dp="http://www.datapower.com/extensions"> 
<xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/> 
<xsl:template match="/"> 
    <xsl:apply-templates/> 
</xsl:template> 
<xsl:template match="@*|node()"> 
    <xsl:copy> 
     <xsl:apply-templates select="@*|node()"/> 
    </xsl:copy> 
</xsl:template> 
<xsl:template match="headerIn"> 
    <xsl:copy> 
     <xsl:apply-templates select="@*|node()"/> 

     <!-- here i need call another xsl file, I want send 2 parameters taked from input, and to recibe tag poli --> 
     <xsl:call-template name="prueba-call-template"> 
      <xsl:with-param name="param1" select="medio"/> 
      <xsl:with-param name="param2" select="aplicacion"/> 

     </xsl:call-template> 
    </xsl:copy> 
</xsl:template> 

prueba-CALL-template.xsl

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    version="1.0" 
    xmlns:dp="http://www.datapower.com/extensions" 
    xmlns:ser="http://ejemplo.com/servicios"> 
    <xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/> 

    <xsl:param name="teller"/> 
    <xsl:param name="terminal"/> 

    <xsl:template match="/*"> 

     <xsl:variable name="result"> 
     <poli> 
      <teller><xsl:value-of select="$teller"/></teller> 
      <terminal><xsl:value-of select="$terminal"/></terminal> 
     </poli> 
     </xsl:variable> 

    </xsl:template> 
    <poli> <xsl:value-of select="$result"/></poli> 
</xsl:stylesheet> 

答えて

0

あなたが考えている方法で、別のXSLTファイルを呼び出すことはできません。ただし、XSLTファイルを他のファイルにインクルードしてから、XSLTに含まれているテンプレートを呼び出すことはできます。

まず、これまであなたのprueba-CALL-template.xslを変更...

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    version="1.0" 
    xmlns:dp="http://www.datapower.com/extensions" 
    xmlns:ser="http://ejemplo.com/servicios" 
     exclude-result-prefixes="dp"> 
    <xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/> 

    <xsl:template name="prueba"> 
     <xsl:param name="teller"/> 
     <xsl:param name="terminal"/> 
     <poli> 
      <teller><xsl:value-of select="$teller"/></teller> 
      <terminal><xsl:value-of select="$terminal"/></terminal> 
     </poli> 
    </xsl:template> 
</xsl:stylesheet> 

その後、あなたはxsl:include文でメインXSLTこのXSLTを含めることができ

<xsl:include href="prueba-call-template.xsl" /> 

ます正しいテンプレートとパラメータ名を使用するようにxsl:call-templateを変更する必要があります(現行のXSLTではパラメータ "param1"と "param2"を使用していますが、2番目のXSLTでは "teller"と "terminal"を使用します)

だから、
<xsl:call-template name="prueba"> 
    <xsl:with-param name="teller" select="medio"/> 
    <xsl:with-param name="terminal" select="aplicacion"/> 
</xsl:call-template> 

、あなたの主なXSLTは、次のようになります。両方のXSLTは、同じ場所に保存されなければならないことを

<xsl:stylesheet version="1.0" extension-element-prefixes="dp" exclude-result-prefixes="dp" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tns="http://www.example.org/tns" xmlns:dp="http://www.datapower.com/extensions"> 
<xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/> 

<xsl:include href="prueba-call-template.xsl" /> 

<xsl:template match="/"> 
    <xsl:apply-templates/> 
</xsl:template> 

<xsl:template match="@*|node()"> 
    <xsl:copy> 
     <xsl:apply-templates select="@*|node()"/> 
    </xsl:copy> 
</xsl:template> 

<xsl:template match="headerIn"> 
    <xsl:copy> 
     <xsl:apply-templates select="@*|node()"/> 

     <xsl:call-template name="prueba"> 
      <xsl:with-param name="teller" select="medio"/> 
      <xsl:with-param name="terminal" select="aplicacion"/> 
     </xsl:call-template> 
    </xsl:copy> 
</xsl:template> 
</xsl:stylesheet> 

注意。

関連する問題