This is Interesting: Free Magazines for Graphics designers and webmasters
Home > Archive > Mozilla XML > October 2005 > document() loses relative path ...
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
document() loses relative path ...
|
|
| Rui Paiva 2005-09-19, 7:35 pm |
| Hi everyone,
I am having a kind of complicated problem....
In trying to write an application that works exclusively on a browser, I am
hitting a wall when it comes to the
usage of the document() XPath function.
I am using a xslt that opens several XML documents.
I am doing several passes on demand, depending of user selections, in order
not to load all the XML files on startup (there are too many files and it
would slow things down).
The XML data I want to process is organised as follows:
dir1/d1.xml
dir1/dir2/d2.xml
dir1/dir3/d3.xml
dir1/dir3/dir4/d4.xml
What I am doing:
Loading the XSLT and the first XML document into 2 DOMs
(document.implementation.createDocument( "", "", null );)
transforming the XML into another XML using ( processor.transformToDocument
(xmlDom, document);.)
The resulting XML document includes
<d1>
<file>d1.xml</file>
<relative>.</relative>
<d2>
<file>d2.xml</file>
<relative>./dir2</relative>
</d2>
<d3>
<file>d3.xml</file>
<relative>./dir3</relative>
</d3>
</d1>
This result works fine... It seems that the first execution of the
document() function's relative path is relative to the base (first
(d1))document I am using.
But when I try to expand the D3 node, executing the xsl again, the processor
has lost it's base path pointer, and I can't open another document unless I
use absolute paths, something I wanted to avoid...
Any idea how the parses is calculating the relative paths ?
Here's a copy of the XSL...
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">
<xsl:output method="xml" version="1.0" encoding="ISO-8859-1" />
<!-- Name of the selected library -->
<xsl:param name="selectedRelativePath" />
<xsl:param name="selectedLibraryName" />
<xsl:template match="/" >
<xsl:if test="PictureFileList" >
<FileList xml:base="." currentFileList="true" expanded="true" >
<RelativePath>
<xsl:value-of select="$selectedRelativePath" />
</RelativePath>
<RelativeLocation>
<xsl:value-of select="$selectedRelativePath" />
</RelativeLocation>
<FileName>
<xsl:value-of select="concat ( $selectedLibraryName, '.xml' )" />
</FileName>
<xsl:copy-of select="PictureFileList/Name" />
<xsl:call-template name="expandChildren" >
<xsl:with-param name="childList"
select="PictureFileList/PictureFileList" />
<xsl:with-param name="relativePath" select="'.'" />
</xsl:call-template >
</FileList >
</xsl:if >
<xsl:if test="not ( PictureFileList ) " >
<xsl:variable name="selectedNode" select="//FileList[ ( Name/text() =
$selectedLibraryName ) and ( RelativePath/text() =
$selectedRelativePath ) ]" />
<xsl:call-template name="recurseFileLists" >
<xsl:with-param name="currentNode" select="node()" />
<xsl:with-param name="selectedNode" select="$selectedNode" />
</xsl:call-template >
</xsl:if >
</xsl:template >
<xsl:template name="recurseFileLists" >
<xsl:param name="currentNode" />
<xsl:param name="selectedNode" />
<xsl:variable name="isSelected" select=" $currentNode = $selectedNode " />
<xsl:variable name="isAncestorOfSelected" select=" count (
$currentNode/descendant::FileList [. = $selectedNode ] ) > 0 " />
<xsl:variable name="hasPictureFileListChildren" select=" count (
$currentNode/child::PictureFileList ) > 0 " />
<FileList >
<xsl:if test="$isSelected" >
<xsl:if test="$selectedNode/@expanded = 'true'" >
<xsl:attribute name="expanded">false</xsl:attribute>
<xsl:copy-of select="$selectedNode/child::* |
$currentNode/@currentFileList | $currentNode/@xml:base" />
</xsl:if >
<xsl:if test="not ( $selectedNode/@expanded = 'true' ) " >
<xsl:attribute name="expanded">true</xsl:attribute>
<xsl:if test="$hasPictureFileListChildren" >
<xsl:variable name="relativePath" select="concat (
$selectedNode/parent::FileList/RelativePath, '/',
$selectedNode/RelativeLocation )" />
<RelativePath>
<xsl:value-of select="$relativePath" />
</RelativePath>
<xsl:call-template name="expandChildren" >
<xsl:with-param name="childList"
select="$selectedNode/PictureFileList" />
<xsl:with-param name="relativePath" select="$relativePath" />
</xsl:call-template >
</xsl:if >
<xsl:if test="not ( $hasPictureFileListChildren ) " >
<xsl:copy-of select="$currentNode/child::* |
$currentNode/@currentFileList | $currentNode/@xml:base" />
</xsl:if >
</xsl:if >
</xsl:if >
<xsl:if test="$isAncestorOfSelected" >
<xsl:copy-of select="$currentNode/RelativePath | $currentNode/FileList |
$currentNode/Name" />
<xsl:for-each select="$currentNode/FileList" >
<xsl:call-template name="recurseFileLists" >
<xsl:with-param name="currentNode" select="." />
<xsl:with-param name="selectedNode" select="$selectedNode" />
</xsl:call-template >
</xsl:for-each >
</xsl:if >
<xsl:if test=" not ( $isAncestorOfSelected or $isSelected ) " >
<xsl:copy-of select="$currentNode/RelativePath | $currentNode/FileList |
$currentNode/Name" />
</xsl:if >
</FileList >
</xsl:template >
<xsl:template name="expandChildren" >
<xsl:param name="childList" />
<xsl:param name="relativePath" />
<xsl:for-each select="$childList" >
<FileList expanded="false">
<xsl:attribute name="xml:base" >
<xsl:value-of select="RelativeLocation " />
</xsl:attribute >
<RelativePath>
<xsl:value-of select="concat ($relativePath, '/', RelativeLocation) "
/>
</RelativePath>
<xsl:copy-of select="Name | RelativeLocation | FileName" />
<xsl:variable name="fileLocation" >
<xsl:element name="fileLocation" >
<xsl:value-of select="concat ($relativePath, '/', RelativeLocation,
'/', FileName) " />
</xsl:element >
</xsl:variable >
<xsl:if test="count (ancestor::*) < 2" >
<xsl:copy-of
select="document($fileLocation)/PictureFileList/PictureFileList" />
</xsl:if >
<xsl:if test="count (ancestor::*) > 1" >
<xsl:copy-of
select="document('br2.xml')/PictureFileList/PictureFileList" />
</xsl:if >
</FileList >
</xsl:for-each >
</xsl:template >
</xsl:stylesheet>
| |
| Axel Hecht 2005-09-21, 7:39 pm |
| We'd need a stripped down testcase for this, just the logic.
That said, I'm not sure that this doesn't work as expected, as the
baseURI for the document function is the stylesheet node (which doesn't
change, if I understood you correctly). You could specify a second
argument to the document() function giving a node to be used as baseURI.
Axel
| |
| Rui Paiva 2005-10-04, 6:53 pm |
| Thanks Axel... The second argument for the base URI in the document function
worked like a charm... in FireFox!
Unfortunately, I have no idea why it is not working in IE.
I know this is not the most appropriate forum for discussing this, but I
thought somebody could have an idea...
Here's the link, and I left the popup that shows the XML tree to help
debugging...
http://ruipaiva.dnip.net/pbnew/PictureLibrary.html
What I am doing is the following:
I have a base XML document with a list of children XML documents, including
their relative paths from the base document (The base document's relative
path is a constant). The children are included inside the parent using the
document() function.
Whenever I expand a node (please see the link), if I still have child nodes,
I also expand those children using the xpath:document () function. This
creates a relative tree structure, that I can navigate at will.
Since I am aways using relative paths to the base document, everything
should work fine.
BUT, on IE, it only seems to work on the first transformation. I suspect
that IE is not using the same base document node for every transformation it
is making, but I have no idea on why this is happening...
Can anybody help ?
If not, can anybody point me to a forum that could help ?
Thanks !
Best regards.
Rui
"Axel Hecht" <axel@pike.org> wrote in message
news:dgrhbv$j4d1@ripley.aoltw.net...
> We'd need a stripped down testcase for this, just the logic.
>
> That said, I'm not sure that this doesn't work as expected, as the baseURI
> for the document function is the stylesheet node (which doesn't change, if
> I understood you correctly). You could specify a second argument to the
> document() function giving a node to be used as baseURI.
>
> Axel
|
|
|
| | Copyright 2003 - 2008 forum4designers.com Software forum Computer Hardware reviews |
|