How to value-of in copy-of in document to merge ?

Discussion in 'XML' started by volunteer@spatiallink.org, Jun 21, 2006.

  1. Guest

    SIMPLE VERSION OF THE QUESTION:
    XML_TO_COPY.XML
    <?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl"
    href="xsl_that_tries_to_copy_but_does_not_work.xsl"?>
    <fruits date="20060621">
    <fruit name="orange" />
    </fruits>

    COPY_RESULT_THAT_IS_INTENDED.XML
    orange

    XSL_THAT_TRIES_TO_COPY_BUT_DOES_NOT_WORK.XSL
    <?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:eek:utput
    method="xml" indent="yes" /><xsl:template match="/">
    <!-- ?!: this or something similar -->
    <xsl:copy-of select="document('20060618.xml')/fruits/fruit[value-of
    select='@name']" />
    </xsl:template>
    </xsl:stylesheet>

    CRYPTIC VERSION OF THE QUESTION:
    I have such xml files stored by dates. On user input for a date range,
    I intend to merge that many xml files and output their fruit names.

    Thanks in advance.
     
    , Jun 21, 2006
    #1
    1. Advertising

  2. Joris Gillis Guest

    On Wed, 21 Jun 2006 16:27:00 +0200,
    <> wrote:

    > <xsl:template match="/">
    > <!-- ?!: this or something similar -->
    > <xsl:copy-of select="document('20060618.xml')/fruits/fruit[value-of
    > select='@name']" />
    > </xsl:template>


    Hi,

    2 problems with this code:

    1) the xpath makes no sense; I suppose you rather want this:
    document('20060618.xml')/fruits/fruit/@name
    2) there's no use copying an attribute node when you haven't got an
    element in the result tree that should get that attribute

    I guess you just want the _value_ of the attribute copied, not the
    attribute itself.
    Give this a try:
    <xsl:apply-templates select="document('20060618.xml')/fruits/fruit/@name"
    />

    regards,
    --
    Joris Gillis (http://users.telenet.be/root-jg/me.html)
    Gaudiam omnibus traderat W3C, nec vana fides
     
    Joris Gillis, Jun 21, 2006
    #2
    1. Advertising

  3. Guest

    Joris,
    During my previous failed attempts, the closest I got to accessing the
    attribute value in some way was through this:

    <xsl:copy-of select="document('20060618.xml')/fruits/fruit[@name =
    'orange']" />

    I even tried nesting <xsl:value-of...> within <xsl:copy-of...>, but it
    didn't work.

    Thanks for your solution. I tried it within and without <xsl:template
    match="/"></xsl:template>, but it doesn't work.

    Regards,
     
    , Jun 21, 2006
    #3
  4. Guest

    I may not have to use xsl:copy-of. I may have to use xsl:variable.
    Anyway, more failed attempts:

    [1]
    <xsl:template match="document('20060618.xml')/fruits">
    <xsl:for-each select="fruit">
    <xsl:value-of select="@name"/>
    </xsl:for-each>
    </xsl:template>

    [2]
    <xsl:template match="/">
    <xsl:for-each select="document('20060618.xml')/fruits/fruit">
    <xsl:value-of select="@name" />
    </xsl:for-each>
    </xsl:template>

    Regards,
     
    , Jun 21, 2006
    #4
  5. Joris Gillis Guest

    On Thu, 22 Jun 2006 00:23:02 +0200,
    <> wrote:

    > I may not have to use xsl:copy-of. I may have to use xsl:variable.
    > Anyway, more failed attempts:
    >
    > [1]
    > <xsl:template match="document('20060618.xml')/fruits">
    > <xsl:for-each select="fruit">
    > <xsl:value-of select="@name"/>
    > </xsl:for-each>
    > </xsl:template>
    >
    > [2]
    > <xsl:template match="/">
    > <xsl:for-each select="document('20060618.xml')/fruits/fruit">
    > <xsl:value-of select="@name" />
    > </xsl:for-each>
    > </xsl:template>
    >
    > Regards,


    * Do you have any access at all to this '20060618.xml' document?

    Run this to check it:

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">
    <xsl:eek:utput method="xml"/>

    <xsl:template match="/">
    <xsl:copy-of select="document('20060618.xml')"/>
    </xsl:template>

    </xsl:stylesheet>
    - Do you seen any output? Can you acces the 'fuit' elements? Is it just
    the attribute that's bothering you?
    - If not, try:

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">
    <xsl:eek:utput method="xml"/>

    <xsl:template match="/">
    <xsl:copy-of select="."/>
    </xsl:template>

    </xsl:stylesheet>

    - anything?
    - is the name '20060618.xml' correct?
    - Does it work when you include a full path name?
    - maybe your xslt processor doesn't get permission to read he file? Maybe
    it's a browser?

    * Maybe the 20060618.xml document has a default namespace you didn't tell
    us about?
    - You'd have to include that namespace in the xslt

    * What's <?xml-stylesheet type="text/xsl"
    href="xsl_that_tries_to_copy_but_does_not_work.xsl"?> doing in
    XML_TO_COPY.XML?
    - If this is the source xml document with which the xslt does it magic,
    why then use 'document()'?
    - You speak of a merge, yet I only see one document.

    Out of ideas:)

    regards,
    --
    Joris Gillis (http://users.telenet.be/root-jg/me.html)
    Gaudiam omnibus traderat W3C, nec vana fides
     
    Joris Gillis, Jun 22, 2006
    #5
    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. Replies:
    1
    Views:
    412
    Joe Kesselman
    Jun 22, 2006
  2. Alex
    Replies:
    2
    Views:
    1,288
  3. Replies:
    26
    Views:
    2,176
    Roland Pibinger
    Sep 1, 2006
  4. lee_j
    Replies:
    6
    Views:
    180
    lee_j
    Nov 27, 2003
Loading...

Share This Page