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

V

volunteer

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.
 
J

Joris Gillis

<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,
 
V

volunteer

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,
 
V

volunteer

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,
 
J

Joris Gillis

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,
 

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

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top