This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Keys across multilple input files
- To: Annmarie dot Rubin at East dot Sun dot COM, Jeni dot Tennison at epistemics dot co dot uk
- Subject: Re: Keys across multilple input files
- From: Ann Marie Rubin - Sun PC Networking Engineering <Annmarie dot Rubin at East dot Sun dot COM>
- Date: Tue, 6 Jun 2000 16:18:15 -0400 (EDT)
- Cc: xsl-list at mulberrytech dot com
- Reply-To: xsl-list at mulberrytech dot com
Thanks Jeni,
I tried your solution without much success. The stylesheet runs without error but does not generate
ancestor or descendant classes. I formatted the filelist.xml as you did in your example. and defined
the documents variable:
<xsl:variable name="documents" select="document('filelist.xml')/documents/doc/@href" />.
I'm not sure what I'm missing.
I did get the hierarchy data when I used the following filelist.xml and stylehseet code. But this
technique searches the root hierarchy for each XML file listed in filelist.xml - probably not very
efficient. I could not seem to get keys to work and get hierarchy info.
filelist.xml
=============
<?xml version="1.0"?>
<someURIs>
<file>CIM_Controller.xml</file>
<file>CIM_LogicalElement.xml</file>
<file>CIM_SoftwareElement.xml</file>
<file>CIM_DiagnosticSetting.xml</file>
<file>CIM_ManagedSystemElement.xml</file>
<file>Solaris_Package.xml</file>
</someURIs>
stylesheet
==========
<xsl:template match="CLASS" mode="hierarchy">
<xsl:variable name="parentname" select="@SUPERCLASS"/>
<xsl:for-each select="document('filelist.xml')/someURIs/file/text()">
<xsl:variable name="current_file_root" select="document(string(.))"/>
<xsl:apply-templates select="$current_file_root//CLASS[@NAME=$parentname]"
mode="hierarchy"/>
</xsl:for-each>
</xsl:template>
Note that in this case, if I do not assign the root node of each document listed in filelist.xml, no
hierarchy classes are generated.
Ann Marie
X-Sender: JTennison@NTServer
To: Annmarie.Rubin@east.sun.com
From: Jeni Tennison <Jeni.Tennison@epistemics.co.uk>
Subject: Re: Keys across multilple input files
Cc: xsl-list@mulberrytech.com
Mime-Version: 1.0
Content-Transfer-Encoding: 8bit
X-MDaemon-Deliver-To: Annmarie.Rubin@East.Sun.COM
Ann Marie,
Thank you for asking this question. My understanding of how keys and
documents interact has been much expanded in trying to answer it. I have
managed to put together something that will probably work, though obviously
I've simplified a few things rather than use the full complexity of what I
know of what you're trying to do. I'm sure you can fill in the gaps.
You say that you have a file named filelist.xml that holds the names of the
XML class files. I'm going to assume it looks something like:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="test.xsl"?>
<documents>
<doc href="test1.xml" />
<doc href="test2.xml" />
<doc href="test3.xml" />
</documents>
I'm also going to assume that it's the 'input file' for when you run the
stylesheet. If it isn't, you can always refer to it using
document('filelist.xml').
On to the stylesheet. First, we set up a variable that holds the contents
of all those documents:
<xsl:variable name="documents" select="document(/documents/doc/@href)" />
Note that the way the document() function works, it actually goes and gets
*all* those documents, not just the first one. Don't ask me why because I
can't follow the definition of document(), but it works. Which is handy.
Next I define the key in the normal way:
<xsl:key name="classes" match="class" use="@name" />
Now, for lack of a better thing to do, I'm going to work through these
classes one at a time according to the order the documents have been given
in and the order the classes have been given in within those documents.
You probably have some more sophisticated way of ordering your output.
Slot it in here.
<xsl:template match="/">
<xsl:for-each select="$documents">
<xsl:apply-templates select="/classes/class" />
</xsl:for-each>
</xsl:template>
For each of the classes, I'm going to have a bit of information about the
class, and then generate the hierarchy that you (used to) want. You
definitely have a more sophisticated output for each class. Slot it in here.
<xsl:template match="class">
<h3><xsl:value-of select="@name" /></h3>
<xsl:apply-templates select="." mode="hierarchy" />
</xsl:template>
And finally, the bit where we use the key() function to get the superclass
node to build the hierarchy. Note that we have to define a variable for
the name of the superclass outside the xsl:for-each. The key() function
works in exactly the same way as normal, but the xsl:for-each defines the
documents that the key is used within. You definitely have a more
sophisticated output for the formatting and linking of the hierarchy. Slot
it in here.
<xsl:template match="class" mode="hierarchy">
<xsl:variable name="superclass" select="@superclass" />
<xsl:for-each select="$documents">
<xsl:apply-templates select="key('classes', $superclass)"
mode="hierarchy" />
</xsl:for-each>
+- <xsl:value-of select="@name" />
</xsl:template>
As I said, I don't understand exactly why or how this works, and will be
glad to see anyone explain the technical ins and outs. But it gives the
desired output in SAXON, which I guess is all that matters in the end.
I hope that helps,
Jeni
Dr Jeni Tennison
Epistemics Ltd, Strelley Hall, Nottingham, NG8 6PE
Telephone 0115 9061301 • Fax 0115 9061304 • Email
jeni.tennison@epistemics.co.uk
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list