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

volunteer

Usenet Archive
Joined
May 31, 2006
Messages
5
Reaction score
0
SIMPLY VERSION OF THE QUESTION:
XML_TO_COPY.XML
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="xsl_that_copies.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.
 

Joe Kesselman

Usenet Archive
Joined
Feb 3, 2006
Messages
1,229
Reaction score
0
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.

Your simplified example doesn't match your question, unfortunately. But some components:

1) User input: That's typically either stylesheet parameters given at time of execution, or an index file which is presented to the stylesheet as input. Pick one, determine its syntax, and figure out how you're going to retrieve/generate the names of the files from that data.

2) You'll then have to for-each over the files. Note that you're likely to wind up with all the files in memory simultaneously; if they're big, this may not be tenable and you may want to separate the tasks of extracting and merging the data. (Some XSLT processors have hooks specifically to help you manage this kind of scripting-across-multiple-files problem; Xalan does, for example. Useful, but unfortunately nonportable.)

3) To get the value(s) from each document, you want something like <xsl:value-of select="document($filename)/fruits/fruit/@name"/> or, if you want to check the date within the file <xsl:value-of select="document(whatever)/fruits[@date=$datevalue]/fruit/@name"/>

That should be enough to get you started.
 

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
548,049
Messages
3,104,246
Members
248,133
Latest member
DujonT

Latest Threads

Top