1

谁能告诉我,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>

谢谢!

4

1 回答 1

1

它将匹配node具有 的attribute元素子元素的任何元素NAME="entity",并根据VALUE该元素的属性attribute将 重命名nodeaccessoracl然后继续处理其子元素,即给定:

<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.

如果里面有多个,那么<attribute NAME="entity" VALUE="something" />里面的第一个匹配将获胜,即给定nodexsl:whenxsl:choose

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

结果元素将是access,而不是acl因为它在“aclval”之前检查“accessval”。

于 2013-10-29T10:43:48.123 回答