XML file-- XSLT transformation problem with attributes of root element

W

Wolfgang

I'm applying a simple XSLT style sheet to an XML file.
The style sheet is:

http://piru.alexandria.ucsb.edu/~rnott/MetadataMapping/access-report.xsl

The XML file is here:

http://piru.alexandria.ucsb.edu/~rnott/MetadataMapping/dlese-adn.xml

This works fine as long as the root element of the XML file is plain
<itemRecord>, like this:
<?xml version="1.0" ?>
<itemRecord>
<general>
<title>Geology Fieldnotes</title>
.... (and so on)

The problem is that in my real-world application the element
<itemRecord> needs to have attributes
like this:

<itemRecord xmlns="http://adn.dlese.org"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://adn.dlese.org
http://www.dlese.org/Metadata/adn-item/0.6.50/record.xsd">

And whith this latter form of <itemRecord...
the XSLT transformation no longer matches anything (There are no
errors, however, just no output).

Why is that?

Thanks for any help and advice.

Wolfgang,
Santa Barbara, CA
 
P

Patrick TJ McPhee

[...]

% The problem is that in my real-world application the element
% <itemRecord> needs to have attributes
% like this:
%
% <itemRecord xmlns="http://adn.dlese.org"
% xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
% xsi:schemaLocation="http://adn.dlese.org
% http://www.dlese.org/Metadata/adn-item/0.6.50/record.xsd">

Name space declarations aren't ordinary attributes. itemRecord
in this latter case is not simply itemRecord but itemRecord
in the name-space identified by http://adn.dlese.org. You need
to identify it in the same way in your transformation.

You do that by declaring a name-space _with a prefix_ in the
transformation, for instance

<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
version = '1.0'
xmlns:adn='http://adn.dlese.org'>
<xsl:template match='adn:itemRecord'>
...
</xsl:template>
</xsl:stylesheet>


Note that the name-space prefix used in the style sheet doesn't
have to be the same as the one used in your XML document. In this
case, it can't be because you don't use a prefix in your document,
but you must use a prefix in the style sheet.
 
W

Wolfgang

Thanks Patrick, This works.

A small addition for the benefit of future readers of this archive,
every hierarchical element which has a name space in the original
document must have a name space in the XPath expressions, e.g.

<xsl:with-param name="value"
select="adn:itemRecord/adn:general/adn:title" />

Wolfgang
 

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

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top