Subject: RE: [xsl] MERGING 2 XML DOCS WITH dom4j parser From: Lea Allison <Lea.Allison@xxxxxxxxxxxxxx> Date: Thu, 21 Mar 2002 11:12:47 +0100 |
OK, I'll try and make it brief, but not too brief! Its a web app, I'm using a Java servlet to take a page request. The servlet converts the page request (which is a mask), and locates the corrosponding file path to the XML doc. The servlet then loads the XML file, transforms it to another form (at this moment its HTML) and returns it to the users browser for viewing. The XML document contains no navigation itself. The navigation its stored in another XML file, and this file gives the contents structure, masks, paths, user-rights, etc. The servlet uses this page to locate the mask and convert it to a file path for locating the requested doc. The second use of this navigator file is to create an HTML navigation menu that should be combined with the main document so that the user can link to other docuemnts. The user can only see the masked path as a link, the actuall path should remain hidden. There is the possibility to add/choose different Navigator files that can map to different XML documents and different menu structures as required. For example there might be a CUSTOM Navigator giving links to the sales dept, and a SALES Navigator giving a menu structure for their sales requirements, etc. On top of this, their are multiple versions of the all files, one for each language. --- A short XML doc for viewing: <?xml version="1.0" encoding="ISO-8859-1"?> <DOCUMENT language="EN"> <H>About Us</H> <SECTION> <TITLE>Our Offices</TITLE> <P>We are located on the main road...</P> </SECTION> </DOCUMENT> --- A clip of the Navigator doc: <?xml version="1.0" ?> <NAVIGATOR language="EN"> <WEB owner="LeaA" basePath="\\SERVER\DOCS" > <HOME isCategory="no" icon="" hide="no" mask="HOME" path="IT/Web/Welcome"> <PERMISSIONS> <ALLOW user="Everybody" modify="no" read="yes" write="no" /> <ALLOW user="Librarian" modify="yes" read="yes" write="no" /> <ALLOW user="Administrator" modify="yes" read="yes" write="yes" /> </PERMISSIONS> <NAME>My Home Page</NAME> <DESCRIPTION>Welcome to my site</DESCRIPTION> </HOME> <ABOUTUS isCategory="yes" icon="" hide="no" mask="ABOUTUS" path="Commercial/AboutUs"> <PERMISSIONS> <ALLOW user="Everybody" modify="no" read="yes" write="no" /> <ALLOW user="Librarian" modify="yes" read="yes" write="no" /> <ALLOW user="Administrator" modify="yes" read="yes" write="yes" /> </PERMISSIONS> <NAME>About Us</NAME> <DESCRIPTION>About our company</DESCRIPTION> <STOCKS isCategory="no" icon="" hide="no" mask="ABOUTUS/TICKETS" path="Commercial/Stocks> <PERMISSIONS> <ALLOW user="Everybody" modify="no" read="yes" write="no" /> <ALLOW user="Librarian" modify="yes" read="yes" write="no" /> <ALLOW user="Administrator" modify="yes" read="yes" write="yes" /> </PERMISSIONS> <NAME>Stocks</NAME> <DESCRIPTION>About the company stocks</DESCRIPTION> </STOCKS> </BOOKNOW> </WEB> </NAVIGATOR> --- So for example, the user request a link "ABOUTUS/STOCKS". The servlet looks-up this mask, and returns the path "Commercial/Stocks". The servlet modifies this path depending on the document base, and users language. The result could be "C:\Documents\Commercial\Stocks_en.xml" The servlet then loads this file. At this stage we have to files loaded, the Document and the Navigator. The objective now is to return the formated Document to the user with a navigation bar created from the Navigator xml. So I either need to combine these files to create one, then apply a style sheet as normal (the best way I think), or apply a stylesheet to the main Document, and import the Navigator file as a parameter, which is what I'm currently doing, but since both the Navigator file name can change and the language, the imported document is not always the same. So currently, I dynamically add a few new elements to the main Document on loading, this is the Navigator name (eg. WEB) and the language (eg "EN") giving a Document something like: <?xml version="1.0" encoding="ISO-8859-1"?> <DOCUMENT language="EN"> <H>About Us</H> <SECTION> <TITLE>Our Offices</TITLE> <P>We are located on the main road...</P> </SECTION> <CURRENTNODE>ABOUTUS/STOCKS</CURRENTNODE> <LANGUAGE>EN</LANGUAGE> </DOCUMENT> My stylesheet is then happy to use these values. --- Snippet of my XSL: <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:variable name="menu" select="document( concat(//DOCUMENT/NAVIGATOR,"_",//DOCUMENT/LANGUAGE,'.xml') )" /> <xsl:output method="html" /> <xsl:template match="/"> <HTML> <HEAD> <TITLE>My Website</TITLE> </HEAD> <BODY> <xsl:for-each select="$menu"> <TABLE> <TR> <TD> <xsl:call-template name="menu3"> <xsl:with-param name="max">5</xsl:with-param> <xsl:with-param name="tblBgColor">#999999</xsl:with-param> <xsl:with-param name="tblSpacing">1</xsl:with-param> <xsl:with-param name="cellBgColor">#000000</xsl:with-param> <xsl:with-param name="currentNodeBgColor">#cc0000</xsl:with-param> <xsl:with-param name="mouseOverColor">#cc0000</xsl:with-param> </xsl:call-template> </TD> </TR> </TABLE> </xsl:for-each> <xsl:apply-templates /> </xsl:template> <xsl:template match="P"> <P><xsl:apply-templates /></P> </xsl:template> ... ... </xsl:stylesheet> --- call-template menu3 is my xsl that creates the navigation bar according to the Navigator. This only seems to work if it is within the for-each $menu part?? Also, with in this loop, I don't appear to be able to call any elements from the main Document?? So, any ideas? I would ideally, not like to use the document import if possible, as firstly the physical location of the Navigator file is not so flexible, and secondly it means reloading the Navigator file for a second time. Many thanks for your help! Lea -----Original Message----- From: Michael Kay [mailto:michael.h.kay@xxxxxxxxxxxx] Sent: Thursday 21 March 2002 10:35 To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: RE: [xsl] MERGING 2 XML DOCS WITH dom4j parser > The problem I find with this method, is that by using a > parameter / variable > to import the second document I have to use a for-each loop with the > $importedDoc to be able to apply the templates to this data. If you show us exactly how you want to combine your two documents (saying you want one "on top of the other" isn't very clear), and what stylesheet you are using to achieve it, perhaps we can help you write a better stylesheet, one that actually works. Michael Kay Software AG home: Michael.H.Kay@xxxxxxxxxxxx work: Michael.Kay@xxxxxxxxxxxxxx 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] MERGING 2 XML DOCS WITH d, Oleg Tkachenko | Thread | RE: [xsl] MERGING 2 XML DOCS WITH d, Lea Allison |
Re: [xsl] seperating alphanumeric s, Oleg Tkachenko | Date | RE: [xsl] MERGING 2 XML DOCS WITH d, Lea Allison |
Month |