'bound prefix' stylesheet problems

1,331 views
Skip to first unread message

gmills

unread,
Sep 9, 2005, 2:40:37 PM9/9/05
to XSLT
Hello -

I'm trying to write a stylesheet that outputs prefixed tags. I
keep on getting errors telling me that the prefixes are not bound.
Below is the stylesheet. It invariably fails saying that "The prefix dc
for element <dc:Title> is not bound". As far as I can tell, the text
<dc:Title> should just be output in the results. What am I doing wrong?

+++++++++++++++++++++++++++++++++++++++++++++++++++
<?xml version="1.0" encoding="iso-8859-1"?>

<!-- This stylesheet follows suggestions found in
http://www.loc.gov/standards/mods/mods-dcsimple.html -->
<!--
xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
-->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:mets="http://www.loc.gov/METS/"
xmlns:mods="http://www.loc.gov/mods/v3"
extension-element-prefixes="mets mods"
exclude-result-prefixes="mets mods">

<xsl:output method="xml" encoding="iso-8859-1" indent="yes" />

<xsl:variable name="dmnodes"
select="mets:mets/mets:structMap/mets:div/@DMDID"/>

<xsl:template match="mets:mets">

<record>
<header>
<!-- An ark will be generated for each METS doc and mapped to
the METS file name. A Java routine called here will retrieve the
identifer from noid -->
<identifier> </identifier>
<!-- Datestamps in METS headers will be in local time. A Java
routine called here will convert to UTC -->
<datestamp><xsl:value-of select="metsHdr/lastmoddate"/></datestamp>
</header>

<metadata>

<oai_dc:dc
xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/oai_dc/
http://www.openarchives.org/OAI/2.0/oai_dc.xsd">

<xsl:comment>Going through the for-each</xsl:comment>

<xsl:for-each select="id($dmnodes)"><xsl:apply-templates
select="mets:mdWrap" /></xsl:for-each>

</oai_dc:dc>

</metadata>

</record>

</xsl:template>

<xsl:template
match="mets:xmlData/mods:mods/mods:titleInfo/mods:title">
<dc:Title>
<xsl:value-of select="."/>
</dc:Title>
</xsl:template>
</xsl:stylesheet>

************************************************************************

Any help appreciated;

Garey Mills

Joris Gillis

unread,
Sep 9, 2005, 2:44:13 PM9/9/05
to XS...@googlegroups.com
Hi,
Tempore 20:40:37, die 09/09/2005 AD, hinc in XS...@googlegroups.com scripsit gmills <gmi...@library.berkeley.edu>:

> I'm trying to write a stylesheet that outputs prefixed tags. I
> keep on getting errors telling me that the prefixes are not bound.
> Below is the stylesheet. It invariably fails saying that "The prefix dc
> for element <dc:Title> is not bound". As far as I can tell, the text
> <dc:Title> should just be output in the results. What am I doing wrong?
>
> +++++++++++++++++++++++++++++++++++++++++++++++++++
> <?xml version="1.0" encoding="iso-8859-1"?>
>
> <!-- This stylesheet follows suggestions found in
> http://www.loc.gov/standards/mods/mods-dcsimple.html -->
> <!--
> xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/"
> xmlns:dc="http://purl.org/dc/elements/1.1/"
> -->
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> xmlns:mets="http://www.loc.gov/METS/"
> xmlns:mods="http://www.loc.gov/mods/v3"
> extension-element-prefixes="mets mods"
> exclude-result-prefixes="mets mods">
>

you haven't declared the namespace prefix 'dc' at a top level element.

make it:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:mets="http://www.loc.gov/METS/"
xmlns:mods="http://www.loc.gov/mods/v3"
xmlns:dc="http://purl.org/dc/elements/1.1/"
extension-element-prefixes="mets mods"
exclude-result-prefixes="mets mods">

regards,
--
Joris Gillis (http://users.telenet.be/root-jg/me.html)
Ceterum censeo XML omnibus esse utendum

gmills

unread,
Sep 9, 2005, 3:00:36 PM9/9/05
to XSLT
Joris -
Thanks for the reply. It appears to work, but why? Quoting from
"XSLT -- Programmers Reference" by Michael Kay:

"It is only necessary to designate a namespace as an extension element
namespace to distinguish extension elements from literal result
elements" (pg. 282). The <dc:Title> tag is supposed to be a literal
result element. And why isn't it necessary for the <oai_dc:dc ...>
tag, which is also a literal result element? I'm not going to get very
far if I don't understand this.

Thanks again;

Garey Mills

Joris Gillis

unread,
Sep 9, 2005, 4:15:42 PM9/9/05
to XS...@googlegroups.com
Tempore 21:00:36, die 09/09/2005 AD, hinc in XS...@googlegroups.com scripsit gmills <gmi...@library.berkeley.edu>:

>
> Joris -
> Thanks for the reply. It appears to work, but why? Quoting from
> "XSLT -- Programmers Reference" by Michael Kay:
>
> "It is only necessary to designate a namespace as an extension element
> namespace to distinguish extension elements from literal result
> elements" (pg. 282).

That quote is rather irrelevant in this context. The quote is about extension elements.
The problem you had, has to do with plain old namespace declarations (see XML specification), in fact it has nothing to do with XSLT. The XML parsing process will fail because the namespace prefix 'dc' is not bound to a namespace uri. The XSLT processor won't even get a chance to start its job.

> And why isn't it necessary for the <oai_dc:dc ...>
It is necessary. You have declared that namespace in your xslt; apparently you did that unconsciously.

<oai_dc:dc xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/" />

It's best to collect all namespaces you plan to output in the top-level element (xsl:stylesheet)

gmills

unread,
Sep 9, 2005, 4:22:28 PM9/9/05
to XSLT
Joris -

That makes sense. Thanks.

Garey Mills

Reply all
Reply to author
Forward
0 new messages