469,270 Members | 1,026 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,270 developers. It's quick & easy.

XSLT - simple match not matching as expected

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:output 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/
Jul 20 '05 #1
3 2197
In article <PM***************@news.itd.umich.edu>,
<la**@nospam.nosoftwarepatents.edu> 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
Jul 20 '05 #2
Tempore 17:56:15, die Monday 24 January 2005 AD, hinc in foro {comp.text.xml} scripsit <la**@nospam.nosoftwarepatents.edu>:
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:output 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:output 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-v...i?userid=38041)
Laudeo W3C et dona ferens
Jul 20 '05 #3
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/
Jul 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Stefan Siegl | last post: by
7 posts views Thread by Kofi Sarfo | last post: by
4 posts views Thread by Moogy | last post: by
2 posts views Thread by pintihar | last post: by
4 posts views Thread by Adrian von Bidder | last post: by
3 posts views Thread by abhishek.smu | last post: by
2 posts views Thread by Efi Merdler | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.