xsl-list
[Top] [All Lists]

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

2006-12-05 06:56:40
On 12/5/06, Mark Wilson <mark(_at_)knihtisk(_dot_)org> 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

--~------------------------------------------------------------------
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>
--~--