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

RE: Writing a stylesheet to create another XML Documen

Subject: RE: Writing a stylesheet to create another XML Document
From: "Kunal H. Parikh" <kunal@xxxxxxxxxx>
Date: Wed, 3 Apr 2002 02:46:42 +1000
author.xml
Jeni wrote:
==========
>
> You're using the document() function just right, to get hold of the
> content of the Author.xml document. If you're searching for particular
> Authors by id a lot, you should store the Author elements in a global
> variable:
>
> <xsl:variable name="authors"
>               select="document('Author.xml')/AuthorList/Author" />
>
> Or you should use a key to get hold of the Author elements quickly,
> especially if there are a lot of them. There are examples about how to
> do that in the XSLT Rec, but ask if you want to see how.

Hey Jeni!

I'd greatly appreciate if you could comment on using the key function in
this scenario.


Thanks a ton!

Kunal


-----Original Message-----
From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
[mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Jeni
Tennison
Sent: Tuesday, 2 April 2002 18:27
To: Kunal H. Parikh
Cc: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re:  Writing a stylesheet to create another XML Document

Hi Kunal,

> I am trying to combine two XML Documents:
>
>         Tutorial.xml, and
>         Author.xml
>
> using the stylesheet TutorialWithAuthorName.xsl
>
> For starters, I don't even know if my stylesheet will work to
> include the Author.xml/AuthorList/Author/Name.

You're using the document() function just right, to get hold of the
content of the Author.xml document. If you're searching for particular
Authors by id a lot, you should store the Author elements in a global
variable:

<xsl:variable name="authors"
              select="document('Author.xml')/AuthorList/Author" />

Or you should use a key to get hold of the Author elements quickly,
especially if there are a lot of them. There are examples about how to
do that in the XSLT Rec, but ask if you want to see how.
  
> Once I get that sorted, I was wondering if an XML file could be
> generated to include the Author.xml/AuthorList/Author/Name ?

Well, you could copy the Author elements wherever you want in the XML
document that you generate with xsl:copy-of. For example to copy the
Author whose id attribute had the value '1', you could use:

  <xsl:copy-of select="$authors[@id = '1']" />

Of course you have to work out where you want to put them within the
result document. You should probably process the Tutorial.xml source
document using an identity template such as:

<xsl:template match="node()|@*">
  <xsl:copy>
    <xsl:apply-templates select="node()|@*" />
  </xsl:copy>
</xsl:template>

This works recursively down the node tree for Tutorial.xml, copying
everything as it goes. Then you could have a template for the Author
elements in Tutorial.xml, which looks at the id attribute and then
copies the Author element from Author.xml that has the same id:

<xsl:template match="Author">
  <xsl:variable name="id" select="@id" />
  <xsl:copy-of select="authors[@id = $id]" />
</xsl:template>

> Also, will this XML file be "live". I.E. will it change each time
> the Author.xml has been changed ?

That depends on how you generate the file. It will update each time
you run the transformation -- each time you run it, the Author.xml
document will be accessed and its contents used to generate the result
document that includes the Author names. The document that gets
generated is just like any other XML document -- it isn't linked to
the documents that generated it, so it doesn't get updated
automatically.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 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-2011 All Rights Reserved.