2013-10-29 87 views
1

任何人都可以告訴我,XSLT在這裏做什麼?它是更長的XSLT文檔的一部分。這個XSLT片段是做什麼的?

<xsl:template match="node[child::attribute[@NAME='entity']]"> 
<xsl:choose> 
    <xsl:when test="child::attribute[@NAME='entity']/@VALUE='accessval'"> 
     <xsl:element name="access"> 
      <xsl:apply-templates /> 
     </xsl:element> 
    </xsl:when> 
    <xsl:when test="child::attribute[@NAME='entity']/@VALUE='aclval'"> 
     <xsl:element name="acl"> 
      <xsl:apply-templates /> 
     </xsl:element> 
    </xsl:when> 
    </xsl:choose> 
</template> 

謝謝!

回答

1

這將匹配具有與NAME="entity"一個attribute子元素任何node元素,並基於該attribute元素的VALUE屬性將重新命名node要麼accessacl,然後繼續處理其子,即給定:

<node> 
    <attribute NAME="entity" VALUE="accessval"/> 
    <!-- other elements here --> 
</node> 

它會產生

<access> 
    <!-- result of applying templates to "attribute" and "other elements here" --> 
</access> 

如果VALUE是「aclval」,它會產生一個名爲acl的元素,而不是access

如果有該node那麼第一匹配xsl:whenxsl:choose內會贏得內部多個<attribute NAME="entity" VALUE="something" />,即給定

<node> 
    <attribute NAME="entity" VALUE="aclval"/> 
    <attribute NAME="entity" VALUE="accessval"/> 
    <!-- other elements here --> 
</node> 

產生的要素是access,不acl因爲它會檢查「 accessval「在」aclval「之前。