XSLT - simple match not matching as expected

L

lars

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

Richard Tobin

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
 
J

Joris Gillis

Tempore 17:56:15 said:
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,
 
L

lars

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

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top