Subject: RE: [xsl] Writing a stylesheet to create another XML Document From: "Kunal H. Parikh" <kunal@xxxxxxxxxx> Date: Wed, 3 Apr 2002 04:45:11 +1000 |
G'Day Jeni! Thanks a lot for all the help provided. According to your email, I have modified the files (Included) However, I don't get any output .... in IE 6. Do I need to use another XML Parser instead of MSXML ? TIA, Kunal H. Parikh Identity.xsl (NEW File) *********************** <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="node()|@*"> <xsl:copy> <xsl:apply-templates select="node()|@*" /> </xsl:copy> </xsl:template> </xsl:stylesheet> *********************** TutorialWithAuthorName.xsl (YES Modified) ***************************************** <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:import href="Identity.xsl"/> <xsl:variable name="authors" select="document('Author.xml')/AuthorList/Author" /> <xsl:template match="Author"> <xsl:variable name="id" select="@id" /> <xsl:copy-of select="authors[@id = $id]" /> </xsl:template> </xsl:stylesheet> ***************************************** Tutorial.xml (NOT Modified) *************************** <?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href="TutorialWithAuthorName.xsl" ?> <Tutorial> <AuthorList> <Author id="1" /> <Author id="2" /> <Author id="3" /> <Author id="4" /> </AuthorList> </Tutorial> *************************** Author.xml (NOT Modified) ************************* <?xml version="1.0"?> <AuthorList> <Author id="1"> <Name>Ms. A B C</Name> </Author> <Author id="2"> <Name>Ms. D E F</Name> </Author> <Author id="3"> <Name>Ms. G H I</Name> </Author> <Author id="4"> <Name>Ms. J K L</Name> </Author> </AuthorList> ************************* -----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: [xsl] 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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Writing a stylesheet to c, Jeni Tennison | Thread | Re: [xsl] Writing a stylesheet to c, Jeni Tennison |
Re: [xsl] xsl value-of, Jeni Tennison | Date | RE: [xsl] xsl value-of, Matias Woloski |
Month |