Shorthand for namespaces

Discussion in 'XML' started by Foxpointe, Oct 31, 2006.

  1. Foxpointe

    Foxpointe Guest

    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
    Foxpointe, Oct 31, 2006
    #1
    1. Advertising

  2. * 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'.
    --
    Björn Höhrmann · mailto: · http://bjoern.hoehrmann.de
    Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
    68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/
    Bjoern Hoehrmann, Oct 31, 2006
    #2
    1. Advertising

  3. 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.

    --
    () ASCII Ribbon Campaign | Joe Kesselman
    /\ Stamp out HTML e-mail! | System architexture and kinetic poetry
    Joe Kesselman, Oct 31, 2006
    #3
  4. Foxpointe

    Foxpointe Guest

    Bjoern Hoehrmann wrote:
    > * 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'.


    That makes sense and thanks for clearing that up for me.
    Foxpointe, Oct 31, 2006
    #4
  5. Foxpointe

    Foxpointe Guest

    Joe Kesselman wrote:
    > 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.
    Foxpointe, Oct 31, 2006
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. foreach shorthand

    , Mar 25, 2005, in forum: C++
    Replies:
    2
    Views:
    565
    =?iso-8859-1?Q?Ali_=C7ehreli?=
    Mar 25, 2005
  2. David W
    Replies:
    0
    Views:
    849
    David W
    Jan 17, 2007
  3. Replies:
    7
    Views:
    383
  4. Tilman  Kispersky
    Replies:
    2
    Views:
    360
    Paul Hankin
    Jun 8, 2008
  5. asit
    Replies:
    4
    Views:
    3,547
    Roedy Green
    Jul 3, 2008
Loading...

Share This Page