Alp
Alp

Reputation: 29739

Use XML schema groups in XSL transformation

I have group definitions in an XML schema. Like so:

<attributeGroup name="my_attributes">
    <attribute ref="ns:foo" />
    <attribute ref="ns:bar" />
</attributeGroup>

Also, I have an XML transformation, in which I want to be able to reuse these definitions. Is it possible to create a template that matches such a group? Something like this maybe:

<xsl:template matchGroup="my_attributes">
    <foobar>
        <xsl:copy-of select="@*"/>
        <xsl:value-of select="." />
    </foobar>
</xsl:template>

Upvotes: 2

Views: 134

Answers (1)

Dimitre Novatchev
Dimitre Novatchev

Reputation: 243449

Is it possible to create a template that matches such a group? Something like this maybe:

<xsl:template matchGroup="my_attributes"> 
    <foobar> 
        <xsl:copy-of select="@*"/> 
        <xsl:value-of select="." /> 
    </foobar> 
</xsl:template>

No, the XSLT <xsl:template> instruction doesn't have a matchGroup attribute and any compliant XSLT processor must raise a syntax error for this reason.

Something like this is probably close to what you are looking for:

<xsl:template match="@ns:foo[../@ns:bar]">
 <!-- Processing here -->
</xsl:template>

The meaning of the match pattern above:

Match any attribute with local-name() foo that is in the namespace to which the prefix "ns:" is associated, and whose "parent" (the ellement this attribute is attached to) *has also another attribute that is named* ns:bar.

Upvotes: 1

Related Questions