无法在xsl中的xml标记内循环

时间:2016-10-27 09:33:31

标签: xslt xslt-1.0 xslt-2.0 ibm-datapower

我有一个用于AAA的自定义xsl来选择经过身份验证的值(输出凭据)并将其传递以进行授权。

我正在使用AAAinfo.xml文件。

AAAinfo.xml:

<?xml version="1.0" encoding="UTF-8"?>
<AAAInfo xmlns="http://www.datapower.com/AAAInfo">
   <Authenticate>
      <OU>****</OU>
      <OutputCredential>****</OutputCredential>
      <OutputCredential>****</OutputCredential>
   </Authenticate>
   <Authenticate>
      <OU>****</OU>
      <OutputCredential>****</OutputCredential>
      <OutputCredential>****</OutputCredential>
   </Authenticate>
   <Authorize>
      <InputCredential>****</InputCredential>
      <InputResource>/****</InputResource>
      <Access>****</Access>
   </Authorize>
   <Authorize>
      <InputCredential>****</InputCredential>
      <InputResource>/****</InputResource>
      <Access>allow</Access>
   </Authorize>
</AAAInfo>

在下面的xsl中,我无法循环到<Authenticate>标签.....

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:dp="http://www.datapower.com/extensions" xmlns:regexp="http://exslt.org/regular-expressions" xmlns:str="http://exslt.org/strings" version="1.0" extension-element-prefixes="dp str regexp" exclude-result-prefixes="dp str regexp">
   <xsl:template match="/">
      <xsl:variable name="AAA_File" select="document('local:///TEST/AAA_data.xml')" />
      <xsl:variable name="DN">
         <xsl:value-of select="dp:variable('var://context/AAA-internal-debug/EI')/identity/entry/dn" />
      </xsl:variable>
      <xsl:variable name="OU_Split1" select="substring-after(normalize-space($DN),'OU=')" />
      <xsl:variable name="OU_Split2" select="substring-before(normalize-space($OU_Split1),'/CN')" />
      <xsl:variable name="OU_Name">
         <xsl:value-of select="regexp:replace($OU_Split2,'/OU=','g','|')" />
      </xsl:variable>
      <xsl:for-each select="$AAA_File/AAA_data/Authenticate">
         <xsl:variable name="OU_File_Name">
            <xsl:value-of select="OU" />
         </xsl:variable>
         <xsl:if test="contains($OU_Name,$OU_File_Name)">
            <xsl:for-each select="OutputCredential">
               <OutputCredential>
                  <xsl:value-of select="." />
               </OutputCredential>
            </xsl:for-each>
         </xsl:if>
      </xsl:for-each>
   </xsl:template>
</xsl:stylesheet>

让我知道如何处理<AAAInfo xmlns="http://www.datapower.com/AAAInfo"> 循环时。

2 个答案:

答案 0 :(得分:0)

感谢所有评论。

解决方案:在样式表中声明相同的命名空间,为其分配前缀并使用该前缀来处理源XML中的元素:

根据已经dec。

xmlns:ns="http://www.datapower.com/AAAInfo"

并循环播放如下

 <xsl:for-each select="$AAA_File/ns:AAAInfo/ns:Authenticate">
 <xsl:variable name = "OU_File_Name">
        <xsl:value-of select="ns:OU"/>
</xsl:variable>

        <xsl:if test = "contains($OU_Name,$OU_File_Name)">
         <xsl:for-each select="ns:OutputCredential">    

答案 1 :(得分:-1)

xsl:for-each select =“$ AAA_File // AAAInfo / Authenticate”&gt;

应该做的诀窍......怒! AAAInfo,而不是AAA_Data。