[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

[xsl] RE: How to give an attribute a QName value, with the appropriate prefix?


Subject: [xsl] RE: How to give an attribute a QName value, with the appropriate prefix?
From: "Costello, Roger L." <costello@xxxxxxxxx>
Date: Tue, 28 Aug 2012 11:45:29 +0000

Thanks Gerrit and Ken.

This works great:

    <xsl:template match="xs:attribute">
          <xsl:copy>
                <xsl:copy-of select="@*" />
                <xsl:variable name="prefix"
select="prefix-from-QName(node-name(.))" />
                <xsl:attribute name="type"><xsl:value-of
select="concat($prefix, if ($prefix eq '') then 'anySimpleType' else
':anySimpleType')" /></xsl:attribute>
                <xsl:sequence select="node()" />
          </xsl:copy>
    </xsl:template>

/Roger

-----Original Message-----
From: Costello, Roger L.
Sent: Monday, August 27, 2012 4:37 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: How to give an attribute a QName value, with the appropriate prefix?

Hi Folks,

I want to transform this:

    <xs:attribute name="test" />

to this:

      <xs:attribute name="test" type="xs:anySimpleType" />

Here is the code that I tried:

    <xsl:template match="xs:attribute">
        <xsl:copy>
            <xsl:copy-of select="@*" />
            <xsl:attribute name="type"><xsl:value-of
select="QName('http://www.w3.org/2001/XMLSchema', 'anySimpleType')"
/></xsl:attribute>
            <xsl:sequence select="node()" />
        </xsl:copy>
    </xsl:template>

Unfortunately that code produces this:

      <xs:attribute name="test" type="anySimpleType" />

Notice that there is no prefix on anySimpleType.

What's the best way to accomplish my objective?

I want the prefix on anySimpleType to match the prefix on the <attribute>
element, whether it be xs: or xsd: or anything else.

/Roger


Current Thread