Shorthand for namespaces

F

Foxpointe

I'd greatly appreciate it if someone could clue me in to a less
verbose/clunky way of accomplishing this: Given some XHTML input, I
need to strip and transform certain tags and while I've currently got a
working solution, it seems like there should be a 'cleaner' way to get
the job done. Given the following snippet...

<xsl:stylesheet version="1.0"
xmlns:xhtml="http://www.w3.org/1999/xhtml"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
exclude-result-prefixes="xhtml"
xmlns="http://www.w3.org/1999/xhtml">

<xsl:template match="xhtml:font | xhtml:b | xhtml:i | xhtml:u">
<!--<xsl:value-of select="."/>-->
<xsl:choose>
<xsl:when test="node()">
<xsl:apply-templates select="node()"/>
</xsl:when>
<xsl:eek:therwise>
<xsl:value-of select="text()"/>
</xsl:eek:therwise>
</xsl:choose>
</xsl:template>

....is there a way to eliminate the need to prefix all of my match terms
with xhtml:? In reading other posts, I was under the impression that
xmlns="http://www.w3.org/1999/xhtml" would set the default namespace but
it didn't do what I expected (i.e. eliminate the need for the prefix)...
so what exactly does it do?

Thanks,
Phil
 
B

Bjoern Hoehrmann

* Foxpointe wrote in comp.text.xml:
<xsl:template match="xhtml:font | xhtml:b | xhtml:i | xhtml:u">
...is there a way to eliminate the need to prefix all of my match terms
with xhtml:? In reading other posts, I was under the impression that
xmlns="http://www.w3.org/1999/xhtml" would set the default namespace but
it didn't do what I expected (i.e. eliminate the need for the prefix)...
so what exactly does it do?

The default namespace declaration declares the default namespace for the
elements in the document (if you had a <p> in the document, it would be
in the default namespace) and it does not affect XPath expressions. The
only more compact way of doing what you do above would be to use a
shorter prefix like 'x'.
 
J

Joe Kesselman

XPath and XSLT 1.0 don't have anything to specifically address the
default namespace declaration; you must use prefixes to specify
namespaced names.

The 2.0 version of these specs has proposed addressing that.
 
F

Foxpointe

Bjoern said:
* Foxpointe wrote in comp.text.xml:


The default namespace declaration declares the default namespace for the
elements in the document (if you had a <p> in the document, it would be
in the default namespace) and it does not affect XPath expressions. The
only more compact way of doing what you do above would be to use a
shorter prefix like 'x'.

That makes sense and thanks for clearing that up for me.
 
F

Foxpointe

Joe said:
XPath and XSLT 1.0 don't have anything to specifically address the
default namespace declaration; you must use prefixes to specify
namespaced names.

The 2.0 version of these specs has proposed addressing that.

Thanks for the heads up on 2.0 and I'll learn to live with the prefix
requirement until then.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top