[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: [XSL] How can I seek info in XML files and tranfor

Subject: RE: [XSL] How can I seek info in XML files and tranform it using XSLT to answer a query
From: "Evan Lenz" <elenz@xxxxxxxxxxx>
Date: Wed, 11 Jul 2001 07:22:39 -0700
xpath seek xmlns
Paul Brown wrote:
> If you don't want the implementation necessarily to be fast, you can spoof
> an XSLT processor into thinking that your collection of files is one large
> document, and that will allow you to use XPath as your query language.

That would be one way of doing it, but it's problematic for maintaining at
least 1) the distinction between documents (whether fragments or
well-formed, since XSLT allows either), 2) the ability to also access
documents using the document() function, and 3) correct behavior of the id()
function (which spans only one document).

I would suggest using another approach which still lets you use XPath as
your query language. Instead of combining all the documents into one tree,
simply create a node-set that consists of all the root nodes of the input
documents. You could then get the URIs of all documents via a config file.
In the example below, I'm assuming the config file is the source tree for
this stylesheet.

Config file:

<documents>
  <document uri="foo.xml"/>
  <document uri="bar.xml"/>
  <document uri="bat.xml"/>
</documents>


Stylesheet:

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

  <!-- selects a set of all the input root nodes -->
  <xsl:variable name="input" select="document(/documents/document/@uri)"/>

  <xsl:for-each select="$input/any/xpath/query">
    <!-- do something -->
  </xsl:for-each>

</xsl:stylesheet>

Note that using $input as the root of your path expression allows you to use
XPath/XSLT as a query language in a very similar way to XQL and XQuery. You
will still be able to use the document() function as another way of
accessing documents specifically by name. Likewise, the id() function will
still continue to work since individual documents retain their identity (and
there won't be any ID clashes between multiple documents). Finally, if you
would like to copy a document or documents whose name you don't know (but
for which a certain query constraint applies), this will work as well
(including the original PIs and comments outside of the document element),
e.g. <xsl:copy-of select="/"/> when you don't know which document the
current node is in.

Hope this helps,

Evan Lenz
XYZFind Corp.

> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of Paul Brown
> Sent: Wednesday, July 11, 2001 6:37 AM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: RE:  [XSL] How can I seek info in XML files and tranform
> it using XSLT to answer a query
>
>
>
> edouard panie:
> > Thanks for answering. I should give some more details:
> > -money is not the issue, I dont have any (it's a
> > school project!)
>
> Since you're a student, you're a very rich man indeed -- you have lots of
> time.
>
> > -the pages will only be accessible to a few people,
> > therefore there won't be more than a few hits a day.
>
> If you don't want the implementation necessarily to be fast, you can spoof
> an XSLT processor into thinking that your collection of files is one large
> document, and that will allow you to use XPath as your query language.
>
> Disclaimer 1: an XML database is going to do a MUCH, MUCH better job than
> the hack below.
>
> Here's how you do it.
>
> 1) Take a look at the old SQL extensions for XalanJ2 or the XSLT-based
> flatfile mapper that I wrote as an example for a Java/XSLT class.
> (http://www.fivesight.com/downloads/xsltflatfile.asp)
>
> 2) Implement a spoof DOM that mirrors the concatenation of your
> directory/file structure and your individual XML files.  For example, this
> means that the implementation of Node that represents a directory has to
> return a list of the files it contains (as wrapping Nodes) when
> getChildNodes() is called.
>
> I would suggest implementing an equivalent<directory name="foo"><file
> name="bar.xml" >[... ...]</file><file name="baz.xml" >[...
> ...]</file></directory>
>
> Where the children of file are the children of the document element of the
> XML document contained in the file.
>
> 3) Do something really, really naughty and make use of how Xalan actually
> traverses XML documents on an xsl:apply-templates call.  (You will NOT be
> able to use xsl:for-each!)  This is present in the examples that I mention
> in (1) above.
>
> Cheers,
>
> - Paul
>
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.