[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: How to give an attribute a QName value, with the

Subject: Re: How to give an attribute a QName value, with the appropriate prefix?
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Mon, 27 Aug 2012 16:41:24 -0400
Re:  How to give an attribute a QName value
At 2012-08-27 20:37 +0000, Costello, Roger L. wrote:
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.

Retrieve it from the namespace axis:


(untested; assumes the default namespace is not the XSD namespace)
<xsl:attribute name="{name(namespace::*[.='http://www.w3.org/2001/XMLSchema'])]}:anySimpleType"
namespace="http://www.w3.org/2001/XMLSchema">
<xsl:copy-of select="node()"/>
</xsl:attribute>


or in XSLT 2.0:

(untested)
<xsl:attribute name="{prefix-from-QName(node-name(.))}:anySimpleType"
     namespace="http://www.w3.org/2001/XMLSchema">
  <xsl:copy-of select="node()"/>
</xsl:attribute>

Remember that node-name(.) gives the QName of the name of the current node, not the name string of the name of the current node.

I hope this helps.

. . . . . . . . . Ken

--
Public XSLT, XSL-FO, UBL and code list classes in Europe -- Oct 2012
Contact us for world-wide XML consulting and instructor-led training
Free 5-hour lecture: http://www.CraneSoftwrights.com/links/udemy.htm
Crane Softwrights Ltd.            http://www.CraneSoftwrights.com/s/
G. Ken Holman                   mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Google+ profile: https://plus.google.com/116832879756988317389/about
Legal business disclaimers:    http://www.CraneSoftwrights.com/legal

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.