Nadine Schöpper
Nadine Schöpper

Reputation: 35

What does this XSLT fragment do?

Can anyone tell me, what the XSLT is doing here? It's a part of a longer XSLT-document.

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

Thank you!

Upvotes: 1

Views: 255

Answers (1)

Ian Roberts
Ian Roberts

Reputation: 122364

It will match any node element that has an attribute element child with NAME="entity", and based on the VALUE attribute of that attribute element it will rename the node to either access or acl and then continue processing its children, i.e. given:

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

it would produce

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

and if the VALUE were "aclval" it would produce an element named acl rather than access.

If there were more than one <attribute NAME="entity" VALUE="something" /> inside the node then the first matching xsl:when inside the xsl:choose would win, i.e. given

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

the resulting element would be access, not acl because it checks for "accessval" before "aclval".

Upvotes: 1

Related Questions