XSLT - simple match not matching as expected

Discussion in 'XML' started by lars@nospam.nosoftwarepatents.edu, Jan 24, 2005.

  1. Guest

    I would expected that the stylesheet below would tag the
    contents of the element "Date" with <b> and </b>, but it doesn't,
    at least not with xsltproc. It just passes the content through
    unchanged.

    I've also tried diffent permutations of upper and lower case.
    What have I missed?

    -Lars

    Stylesheet:

    <xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">

    <xsl:eek:utput omit-xml-declaration="yes"
    method="xml" media-type="text/xml" encoding="utf-8" />

    <xsl:template match="Date">
    <b> <xsl:apply-templates/> </b>
    </xsl:template>

    </xsl:stylesheet>

    Data:
    <?xml version="1.0" encoding="UTF-8" ?>
    <FMPDSORESULT xmlns="http://www.filemaker.com/fmpdsoresult">
    <ROW MODID="3" RECORDID="38">
    <Article_Titles.Title>
    <DATA>Texan city</DATA>
    </Article_Titles.Title>
    <Date>2003-12-22</Date>
    <Article_Quotes.Quote>
    <DATA>The city is about three months</DATA>
    </Article_Quotes.Quote>
    </ROW>
    </FMPDSORESULT>

    --
    Lars
    "Chances are that patents on software ... in fact stifle
    innovation. Europe could still alter course"
    http://www.nosoftwarepatents.com/en/m/intro/
    , Jan 24, 2005
    #1
    1. Advertising

  2. In article <PM9Jd.593$>,
    <> wrote:
    >I would expected that the stylesheet below would tag the
    >contents of the element "Date" with <b> and </b>, but it doesn't,
    >at least not with xsltproc. It just passes the content through
    >unchanged.


    > <FMPDSORESULT xmlns="http://www.filemaker.com/fmpdsoresult">
    >[...]
    > <Date>2003-12-22</Date>


    The Date element is in the http://www.filemaker.com/fmpdsoresult
    namespace.

    > <xsl:template match="Date">
    > <b> <xsl:apply-templates/> </b>
    > </xsl:template>


    This matches Data elements in no namespace. You need to bind a prefix
    for the namespace in the stylesheet, and use it on the template, e.g.

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

    ....

    <xsl:template match="z:Date">

    -- Richard
    Richard Tobin, Jan 24, 2005
    #2
    1. Advertising

  3. Joris Gillis Guest

    Tempore 17:56:15, die Monday 24 January 2005 AD, hinc in foro {comp.text.xml} scripsit <>:

    > I would expected that the stylesheet below would tag the
    > contents of the element "Date" with <b> and </b>, but it doesn't,
    > at least not with xsltproc. It just passes the content through
    > unchanged.
    >
    > I've also tried diffent permutations of upper and lower case.
    > What have I missed?

    It's a namespacing issue. Either declare and use the namespace in the xsl:
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:sfn="http://www.filemaker.com/fmpdsoresult" exclude-result-prefixes="sfn">

    <xsl:eek:utput omit-xml-declaration="yes"
    method="xml" media-type="text/xml" encoding="utf-8" />

    <xsl:template match="sfn:Date">
    <b> <xsl:apply-templates/> </b>
    </xsl:template>

    </xsl:stylesheet>

    or leave it undefined.
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

    <xsl:eek:utput omit-xml-declaration="yes"
    method="xml" media-type="text/xml" encoding="utf-8" />

    <xsl:template match="*[local-name()='Date']">
    <b> <xsl:apply-templates/> </b>
    </xsl:template>

    </xsl:stylesheet>

    The first one is most of the time better.


    regards,
    --
    Joris Gillis (http://www.ticalc.org/cgi-bin/acct-view.cgi?userid=38041)
    Laudeo W3C et dona ferens
    Joris Gillis, Jan 24, 2005
    #3
  4. Guest

    Thanks, Richard and Joris. The namespace issue is something new
    and I will experiment with your suggestions.

    ---
    Lars
    "Chances are that patents on software ... in fact stifle
    innovation. Europe could still alter course"
    http://www.nosoftwarepatents.com/en/m/intro/
    , Jan 26, 2005
    #4
    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. Ian
    Replies:
    2
    Views:
    797
  2. Lars Schouw
    Replies:
    1
    Views:
    368
    Sousuke
    Mar 26, 2010
  3. Marc Bissonnette

    Pattern matching : not matching problem

    Marc Bissonnette, Jan 8, 2004, in forum: Perl Misc
    Replies:
    9
    Views:
    230
    Marc Bissonnette
    Jan 13, 2004
  4. Yash

    Pattern matching for "best match"

    Yash, Jan 28, 2004, in forum: Perl Misc
    Replies:
    9
    Views:
    132
    Gunnar Strand
    Jan 29, 2004
  5. Bobby Chamness
    Replies:
    2
    Views:
    224
    Xicheng Jia
    May 3, 2007
Loading...

Share This Page