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

RE: Root node with attributes

Subject: RE: Root node with attributes
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Thu, 18 Oct 2007 09:47:41 +0100
RE:  Root node with attributes
match="String" matches an element whose local name is "String" and whose
namespace URI is "". By adding
xmlns="http://nxtassembler.sourceforge.net/NXT/AsXML.xsd" to your outermost
element (not the root node!) you have placed all your elements in namespace
"http://nxtassembler.sourceforge.net/NXT/AsXML.xsd", so match="String" will
no longer match.

In XSLT 2.0 you can add 

xpath-default-namespace="http://nxtassembler.sourceforge.net/NXT/AsXML.xsd"

to your xsl:stylesheet element so that unprefixed names like String are
interpreted as being in that namespace.

Michael Kay
http://www.saxonica.com/  

> -----Original Message-----
> From: Matteo Valdina [mailto:zanfire@xxxxxxxxx] 
> Sent: 18 October 2007 08:53
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  Root node with attributes
> 
> Hello,
> 
> I'm tring to understand where is my error and a solution for 
> this problem:
> When the root node conatins attributes the templates are not 
> applied, If the root node don't contain the attributes the 
> templates are applied.
> I didn't understand wath is the right way to apply a template 
> in a root node with attributes.
> 
> Any suggestion are welcome.
> 
> Thanks and sorry for my english
> 
> Matteo Valdina
> 
> Program used: saxon 8
> 
> Stylesheet
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>      version="2.0">
> 
>      <xsl:output method="xml" />
> 
>       <xsl:template match="*|/">
>              <xsl:copy>
>                      <xsl:copy-of select="@*"/>
>                      <xsl:apply-templates />
>              </xsl:copy>
>      </xsl:template>
> 
> 
>       <!-- Transform a string to a Array -->
>      <xsl:template match="String">
>              <xsl:message>Convert String</xsl:message>
>              <Array name="{@name}">
>                      <xsl:for-each 
> select="string-to-codepoints(@value)">
>                              <ArrayData type="UBYTE" value="{.}"/>
>                      </xsl:for-each>
>                      <ArrayData type="UBYTE" value="0"/>
>              </Array>
>      </xsl:template>
> </xsl:stylesheet>
> 
> Input file:
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <Assembly xmlns="http://nxtassembler.sourceforge.net/NXT/AsXML.xsd">
>      <Dataspace>
>              <Data name="a" type="ULONG" value="1"/>
>              <String name="ciao" value="Hello!" />
>      </Dataspace>
> </Assembly>
> 
> Te aspected result is:
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <Assembly xmlns="http://nxtassembler.sourceforge.net/NXT/AsXML.xsd">
>      <Dataspace>
>              <Data name="a" type="ULONG" value="1"/>
>              <Array name="ciao"><ArrayData type="UBYTE" 
> value="72"/><ArrayData type="UBYTE" value="101"/><ArrayData 
> type="UBYTE"
> value="108"/><ArrayData type="UBYTE" value="108"/><ArrayData 
> type="UBYTE" value="111"/><ArrayData type="UBYTE"
> value="33"/><ArrayData type="UBYTE" value="0"/></Array>
>      </Dataspace>
> </Assembly>

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-2011 All Rights Reserved.