xsl-list
[Top] [All Lists]

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

2012-08-28 06:45:44
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(_at_)lists(_dot_)mulberrytech(_dot_)com
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

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--