Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XML file-- XSLT transformation problem with attributes of root element

Reply
Thread Tools

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

 
 
Wolfgang
Guest
Posts: n/a
 
      04-06-2004
I'm applying a simple XSLT style sheet to an XML file.
The style sheet is:

http://piru.alexandria.ucsb.edu/~rno...ess-report.xsl

The XML file is here:

http://piru.alexandria.ucsb.edu/~rno.../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"
xmlnssi="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
 
Reply With Quote
 
 
 
 
Patrick TJ McPhee
Guest
Posts: n/a
 
      04-07-2004
In article <(E-Mail Removed) >,
Wolfgang <(E-Mail Removed)> wrote:

[...]

% The problem is that in my real-world application the element
% <itemRecord> needs to have attributes
% like this:
%
% <itemRecord xmlns="http://adn.dlese.org"
% xmlnssi="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 xmlnssl='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.
--

Patrick TJ McPhee
East York Canada
http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
 
 
 
Wolfgang
Guest
Posts: n/a
 
      04-09-2004
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

(E-Mail Removed) (Patrick TJ McPhee) wrote in message news:<c4vigv$5rm$(E-Mail Removed)>...
> In article <(E-Mail Removed) >,
> Wolfgang <(E-Mail Removed)> wrote:
>
> [...]
>
> % The problem is that in my real-world application the element
> % <itemRecord> needs to have attributes
> % like this:
> %
> % <itemRecord xmlns="http://adn.dlese.org"
> % xmlnssi="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 xmlnssl='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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
XML to another XML format transformation using XSLT Binaryx XML 3 04-14-2012 10:20 PM
xslt not working when xml has xmlns="urn" in root element. Lee XML 3 04-04-2007 06:07 PM
XSLT: Confusion over adding attributes with xml:element and xml:attribute Jordan Willms XML 2 11-09-2004 12:25 AM
Undesired (maybe) attributes in root element of XSLT output Wolfgang XML 1 04-09-2004 04:18 AM
XML file-- XSLT transformation problem with attributes of root element Wolfgang XML 0 04-06-2004 09:31 PM



Advertisments