Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: [xsl] How do templates get invoked for elements decorated with namespaces?

From: "Andrew Welch" <andrew.j.welch@--------->
To:
Date: 12/5/2006 1:57:00 PM
On 12/5/06, Mark Wilson <mark@xxxxxxxxxxxx> wrote:
Hi,



I have no idea how to even look this problem up in the archives. If the
answer is there, I apologize.

I find that a template such as



<xsl:template match="/Workbook">



         <xsl:apply-templates select="DocumentProperties" />



 </xsl:template>



is invoked when the element name is undecorated with a namespace attribute:



 <Workbook>
.
</Workbook>

but is not invoked when the namespace is present:



<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"



 xmlns:o="urn:schemas-microsoft-com:office:office"



 xmlns:x="urn:schemas-microsoft-com:office:excel"



 xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"



 xmlns:html="http://www.w3.org/TR/REC-html40">



...



</Workbook>



How does the template have to be changed to be invoked for the second case?

In the second case <Workbook> is in the namespace
"urn:schemas-microsoft-com:office:spreadsheet" because it's unprefixed
and the default namespace (the one used by unprefixed elements) has
been changed using xmlns="..."

Oddly the same namespace has been defined again for the "ss" prefix,
which is a bit pointless - either <Workbook> should be changed to
<ss:Workbook> and don't change the default namespace, or the "ss"
prefix should be dropped.

Either way, what you need to do to define that namespace in your
stylesheet and give it a prefix, say "ss" as well, then use that
prefix when referring to that element.

For example:



<xsl:stylesheet
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" ........>

and then



<xsl:apply-templates select="ss:Workbook"/>



<xsl:template match="ss:Workbook">



etc



cheers
andrew


transparent
Print
Mail
Digg
delicious
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent