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

Discussion in 'XML' started by Wolfgang, Apr 6, 2004.

  1. Wolfgang

    Wolfgang Guest

    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
     
    Wolfgang, Apr 6, 2004
    #1
    1. Advertising

  2. In article <>,
    Wolfgang <> 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"
    % 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.
    --

    Patrick TJ McPhee
    East York Canada
     
    Patrick TJ McPhee, Apr 7, 2004
    #2
    1. Advertising

  3. Wolfgang

    Wolfgang Guest

    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

    (Patrick TJ McPhee) wrote in message news:<c4vigv$5rm$>...
    > In article <>,
    > Wolfgang <> 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"
    > % 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.
     
    Wolfgang, Apr 9, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Wolfgang
    Replies:
    0
    Views:
    433
    Wolfgang
    Apr 6, 2004
  2. Wolfgang
    Replies:
    1
    Views:
    550
    Patrick TJ McPhee
    Apr 9, 2004
  3. Jordan Willms
    Replies:
    2
    Views:
    854
    Richard Tobin
    Nov 9, 2004
  4. jkflens
    Replies:
    2
    Views:
    1,541
    jkflens
    May 30, 2006
  5. Binaryx
    Replies:
    3
    Views:
    5,264
    Peter Flynn
    Apr 14, 2012
Loading...

Share This Page