XSL:测试一个节点值是否存在于另一个节点中

时间:2021-07-23 03:59:54

标签: xslt

我对这个基本问题表示歉意,因为我对 XSLT 有点陌生。

<?xml version="1.0" encoding="UTF-8"?>
<ike>
    <gateway>
        <entry name="VPN1-IKEV1-128">
            <protocol>
                <ikev1>
                    <ike-crypto-profile>Suite-B-GCM-128</ike-crypto-profile>
                </ikev1>
            <version>ikev1</version>
            </protocol>
        </entry>
    </gateway>
    <crypto-profiles>
        <ike-crypto-profiles>
            <entry name="Suite-B-GCM-128">
                <encryption>
                    <member>aes-128-gcm</member>
                </encryption>
            </entry>
        </ike-crypto-profiles>
    </crypto-profiles>
</ike>

我需要实现的: 如果版本是ikev1 1)。获取其配置的 ike-crypto-profile 名称(Suite-B-GCM-128) 2)。在加密配置文件中查找加密配置文件名称 (Suite-B-GCM-128)。 3)。如果此加密配置文件中有名为“aes-128-gcm 或 aes-256-gcm”的成员,请向用户发送错误消息,因为我们不支持 IKEv1 的 AES-GCM。

这是我的 xsl。它没有按预期工作。


<xsl:template match="/config/global/network/ike/gateway/entry">
   <xsl:variable name="name"       select="@name"/>
   <xsl:variable name="gwname"     select="@gwname"/>
   <xsl:variable name="ver"        select="protocol/version" />
   <xsl:variable name="v1crypto"   select="protocol/ikev1/ike-crypto-profile"/>
                
   <xsl:if test="$ver='ikev1'">
      <xsl:for-each match="/config/global/network/ike/crypto-profiles/ike-crypto-profiles/entry">
         <xsl:if test="@name=$v1crypto">
             <xsl:if test="encryption/member='aes-128-gcm' or encryption/member='aes-256-gcm'">
                 <error> AES-GCM <xsl:value-of select="@name"/>is not supported for IKEv1 gateway <xsl:value-of select="$gwname" /> </error>
             </xsl:if>
         </xsl:if>
      </xsl:for-each>    
   </xsl:if>
</xsl:template>

1 个答案:

答案 0 :(得分:-1)

在这里发布工作过的 XSL,以防有人对此主题感兴趣。

 <xsl:template match="/config/global/network/ike/gateway/entry">
    <xsl:variable name="gwname"     select="@name"/>
    <xsl:variable name="ver"        select="protocol/version"/>
    <xsl:variable name="v1crypto"   select="protocol/ikev1/ike-crypto-profile"/>
 
    <xsl:if test="$ver='ikev1'">
       <xsl:for-each select="/config/global/network/ike/crypto-profiles/ike-crypto-profiles/entry">
         <xsl:if test="@name=$v1crypto">
          <xsl:for-each select="encryption/member">
           <xsl:if test=".='aes-128-gcm' or .='aes-256-gcm' " >
         <error>Not support: <xsl:value-of select="."/> is selected in <xsl:value-of select="@name"/> which is attched to  IKEv1         gateway <xsl:value-of select="$gwname"/></error> <xsl:text>&#10;</xsl:text>
           </xsl:if>
         </xsl:for-each>
         </xsl:if>
       </xsl:for-each>
    </xsl:if>
 </xsl:template>
相关问题