这个xsl中的for-each如何?

时间:2014-05-13 23:36:32

标签: xslt jdeveloper bpel

我从Bpel流程中的服务中获得此结果。 我如何使用OSTypeOutput在其中进行For-each 测试“serv”的值?

我正在尝试进行转型。

<siOutPut>
  -<OOPreOutput xmlns="http://my.web.com/test/types">
    -<OSTypes xmlns:ns1="http://my.web.com/test/servtp">
        -<ns1:OSTypeOutput>
            <ns1:serv>A1</ns1:serv>
            <ns1:serv>A2</ns1:serv>
            <ns1:serv>A3</ns1:serv>
        </ns1:OSTypeOutput>
    </OSTypes>
  </OOPreOutput>
</siOutPut>

我试过这种方式,但我什么也得不到:

  <xsl:param name="Param">
    <xsl:text disable-output-escaping="no">A3</xsl:text>
  </xsl:param>
  <xsl:template match="/">
    <ns1:GetTestResponse>
     <ns1:MyId>
       <xsl:for-each select="/ns1:OOPreOutput/ns1:OSTypes/ns1:OSTypeOutput">
         <xsl:if test="(./serv = $Param)">
           <xsl:value-of select="'Found'"/>
         </xsl:if>  
       </xsl:for-each>
     </ns1:MyId>      
    </ns1:GetTestResponse>
  </xsl:template>

我做了这个测试:

<ns1:MyId>
  <xsl:for-each select="/ns1:OOPreOutput/ns1:OSTypes">
       <xsl:value-of select="current()"/>
   </xsl:for-each>
</ns1:MyId>  

得到这个结果: A1A2A3

我也做了这个测试,但没有结果:

  <xsl:param name="Param">
    <xsl:text disable-output-escaping="no">A3</xsl:text>
  </xsl:param>
  <xsl:template match="/">
    <ns1:GetTestResponse>
     <ns1:MyId>
       <xsl:if test="/ns1:OOPreOutput/ns1:OSTypes/ns1:OSTypeOutput/ns1:serv = $Param">
           <xsl:value-of select="'Found'"/>
       </xsl:if>  
     </ns1:MyId>      
    </ns1:GetTestResponse>
  </xsl:template>

我改变了一点输出:

-<siOutPut>
  -<OOPreOutput xmlns="http://int.clear.com/types">
    +<Deliv></Deliv>
    <OSTypes>
    <ns1:serv xmlns:ns1="http://my.test.com/web/services">A1</ns1:serv>
    <ns1:serv xmlns:ns1="http://my.test.com/web/services">A2</ns1:serv>
    <ns1:serv xmlns:ns1="http://my.test.com/web/services">A3</ns1:serv>
    </OSTypes>
  </OOPreOutput>
</siOutPut>

如何验证ns1:serv是否具有“A3”值?

3 个答案:

答案 0 :(得分:1)

您没有在样式表中声明其中一个命名空间。重写样式表:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns1="http://my.web.com/test/servtp" xmlns:ns2="http://my.web.com/test/types" version="1.0">

<xsl:param name="Param">
    <xsl:text disable-output-escaping="no">A3</xsl:text>
</xsl:param>
<xsl:template match="/">
    <ns1:GetTestResponse>
        <ns1:MyId>
            <xsl:for-each select="/siOutPut/ns2:OOPreOutput/ns2:OSTypes/ns1:OSTypeOutput">
                <xsl:if test="(./ns1:serv = $Param)">
                    <xsl:value-of select="'Found'"/>
                </xsl:if>  
            </xsl:for-each>
        </ns1:MyId>      
    </ns1:GetTestResponse>
</xsl:template>

</xsl:stylesheet>

但是,没有必要为每个人做一个因为你只想检查&#34; serv&#34;的存在。有一些价值。 它也可以这样做:

<xsl:template match="/">
<ns1:GetTestResponse>
    <ns1:MyId>
            <xsl:if test="siOutPut/ns2:OOPreOutput/ns2:OSTypes/ns1:OSTypeOutput/ns1:serv = $Param">
                <xsl:value-of select="'Found'"/>
            </xsl:if>  
    </ns1:MyId>      
</ns1:GetTestResponse>
</xsl:template>

答案 1 :(得分:0)

我尝试使用应用模板来简化逻辑。我认为问题可能是&lt; xsl:value-of select =&#34;&#39;找到&#39;&#34; /&gt;。我说它&lt;&lt;&#; XSL:文本&GT;&#39;实测值&#39;&LT; / XSL:文本取代。而且我认为你没有匹配&lt; siOutPut取代。我不认为&lt; xsl:模板匹配=&#34; /&#34;&gt;解决了它。

<xsl:param name="Param">
 <xsl:text disable-output-escaping="no">A3</xsl:text>
</xsl:param>
<xsl:template match="/">
 <ns1:GetTestResponse>
  <ns1:MyId>
   <xsl:apply-templates />
  </ns1:MyId>      
 </ns1:GetTestResponse>
</xsl:template>

<xsl:template match="ns1:OSTypeOutput">
   <xsl:for-each select="ns1:serv">
     <xsl:if test=".= $Param">
       <xsl:text>'Found'</xsl:text>
     </xsl:if>  
   </xsl:for-each>
</xsl:template>

答案 2 :(得分:0)

更改输出后,我为每个人做了这个并且工作了:

<xsl:for-each select="/ns2:OOPreOutput/ns2:OSTypes">
    <xsl:if test="(./ns1:serv = $Param)">
         <xsl:value-of select="'Found'"/>
    </xsl:if>  
</xsl:for-each>

并按照Lingamurthy的建议进行直接测试

<xsl:if test="ns2:OOPreOutput/ns2:OSTypes/ns1:serv = $Param">
    <xsl:value-of select="'Found'"/>
<xsl:if>

谢谢大家。

相关问题