[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
Re: [xsl] Resetting context to main document with "document()"?
Subject: Re: [xsl] Resetting context to main document with "document()"? From: "Costantino Sertorio" <costantino.sertorio@xxxxxxx> Date: Fri, 8 Mar 2002 14:47:50 +0100 |
Hi Joerg, here is the stylesheet - in order to properly test it I would need to send you also the xml files etc. If necessary, I can send the whole set. The problem is that when I set the variable to "/", it outputs as an error message words from the "templates" file (what I interpreted as trash...), complaining "is not a valid URL". Now I fixed it passing the same pathname twice to the xsl processor, once as the name of the parsed file and once as a simple parameter. Not elegant, isn't it? Thank you very much, Costantino <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version ="1.0"> <xsl:output method="xml" indent="yes"/> <xsl:param name="metadata"/> <xsl:param name="config-local"/> <xsl:param name="effective-date"/> <xsl:param name="templates"/> <xsl:key name="docs" match="text-block" use="concat(@label, '::', @xml:lang)"/> <xsl:template match="/"> <docs> <version> <file>resolve.xsl</file> <comment> <xsl:value-of select="$version"/> </comment> </version> <version> <file><xsl:value-of select ="$templates"/></file> <comment> <xsl:value-of select ="docs/version"/> </comment> </version> <!-- iterate over each doc from metadata.xml --> <xsl:for-each select="document ($metadata)/request/metadata"> <!-- assign the doc to the $doc-ref variable --> <xsl:variable name="doc-ref" select="."/> <xsl:variable name="doc" select="document ($templates)/docs/doc[@label=$doc-ref/Doctype and @xml:lang =$doc-ref/Language and ((@effective-from <= $effective-date and @effective-to >= $effective-date) or (@effective-from < = $effective-date and not(@effective-to)) or (@effective-to > = $effective-date and not(@effective-from)) or (not(@effective-from) and not (@effective-to)) )]"/> <xsl:choose> <xsl:when test="not($doc)"> <error> <name>not-found</name> <description>No document was found with corresponding name, language, and effective date.</description> <label> <xsl:value-of select="$doc-ref/Doctype"/> </label> <language> <xsl:value-of select="$doc-ref/Language"/> </language> <effective-date> <xsl:value-of select="$effective-date"/> </effective-date> </error> </xsl:when> <xsl:when test="count($doc) > 1"> <error> <name>multiple-docs</name> <description> <xsl:value-of select="count($doc)"/> documents with same name, language and overlapping effective dates found. </description> <document-list> <xsl:for-each select="$doc"> <matching-doc> <label> <xsl:value-of select="@label"/> </label> <language> <xsl:value-of select="@xml:lang"/> </language> <effective-from> <xsl:value-of select="@effective-from"/> </effective-from> <effective-to> <xsl:value-of select="@effective-to"/> </effective-to> </matching-doc> </xsl:for-each> </document-list> <label> <xsl:value-of select="$doc-ref/Doctype"/> </label> <language> <xsl:value-of select="$doc-ref/Language"/> </language> <effective-date> <xsl:value-of select="$effective-date"/> </effective-date> </error> </xsl:when> <xsl:otherwise> <doc> <!-- Copy input attributes to output doc element: --> <xsl:for-each select="$doc/@*"> <xsl:attribute name="{name()}"><xsl:value-of select="."/></xsl:attribute> </xsl:for-each> <!-- create the metadata element for the doc --> <metadata> <xsl:copy-of select="*"/> </metadata> <source> <xsl:copy-of select="../source/*"/> </source> <config> <xsl:copy-of select="document($config-local)"/> </config> <!-- change context to templates.xml --> <xsl:for-each select="document($templates)"> <content> <xsl:apply-templates select="$doc/content"> <xsl:with-param name="doc-ref" select="$doc-ref"/> </xsl:apply-templates> </content> </xsl:for-each> </doc> </xsl:otherwise> </xsl:choose> </xsl:for-each> </docs> </xsl:template> <xsl:template match="node()[name() = 'content']"> <xsl:param name="doc-ref"/> <!-- pass the reference through the templates recursively --> <xsl:apply-templates select="node()"> <xsl:with-param name="doc-ref" select="$doc-ref"/> </xsl:apply-templates> </xsl:template> <xsl:template match="paste"> <xsl:param name="doc-ref"/> <!-- pass the reference through the templates recursively --> <xsl:variable name="name" select="."/> <!-- <xsl:variable name="source-metadata" select ="document($metadata)/data/doc/*[name() = $name]"/>--> <xsl:variable name="doc" select="key('docs', concat($name, '::', $doc-ref/Language))"/> <xsl:variable name="source-template" select="$doc"/> <xsl:choose> <!-- Is the element specified in the "paste" tag contained in the metadata file, and in particular in the document request that I am currently considering? --> <xsl:when test="$doc-ref/*[name() = $name]"> <!-- <xsl:apply-templates select ="$doc-ref/*[name() = $name]"/>--> <!-- 12/12/2001, CS: When data is coming from metadata, then the tags are removed; if they come from the templates, then the tags are preserved. --> <xsl:value-of select="$doc-ref/*[name() = $name]"/> </xsl:when> <!-- If not in the metadata, is it a text block contained in the templates file? --> <xsl:when test="$source-template"> <xsl:apply-templates select ="$source-template/node()"> <xsl:with-param name="doc-ref" select="$doc-ref"/> <!-- pass the reference through the templates recursively --> </xsl:apply-templates> </xsl:when> <!-- The element to "paste" was not found: --> <xsl:otherwise> <not-found> <xsl:value-of select="$name"/> </not-found> </xsl:otherwise> </xsl:choose> </xsl:template> <xsl:template match="from-meta"> <xsl:param name="doc-ref"/> <!-- pass the reference through the templates recursively --> <xsl:variable name="name" select="."/> <xsl:choose> <xsl:when test="$doc-ref/*[name() = $name]"> <xsl:if test="document ($config-local)/content/settings/transform/debug='false'"> <!-- 12/12/2001, CS: When data is coming from metadata, then the tags are removed; if they come from the templates, then the tags are preserved. --> <xsl:value-of select ="$doc-ref/*[name() = $name]"/> </xsl:if> <xsl:if test="document ($config-local)/content/settings/transform/debug='true'"> <from-meta><xsl:value-of select ="$name"/></from-meta> </xsl:if> </xsl:when> <!-- The element to "paste" was not found: --> <xsl:otherwise> <not-found> <xsl:value-of select="$name"/> </not-found> </xsl:otherwise> </xsl:choose> </xsl:template> <xsl:template match="from-template"> <xsl:param name="doc-ref"/> <!-- pass the reference through the templates recursively --> <xsl:variable name="name" select="."/> <xsl:variable name="doc" select="key('docs', concat($name, '::', $doc-ref/Language))"/> <xsl:variable name="source-template" select="$doc"/> <xsl:choose> <xsl:when test="$source-template"> <xsl:apply-templates select ="$source-template/node()"> <xsl:with-param name="doc-ref" select="$doc-ref"/> <!-- pass the reference through the templates recursively --> </xsl:apply-templates> </xsl:when> <!-- The element to "paste" was not found: --> <xsl:otherwise> <not-found> <xsl:value-of select="$name"/> </not-found> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet> ------------------------------ Date: Tue, 5 Mar 2002 20:36:02 +0100 From: "Joerg Heinicke" <joerg.heinicke@xxxxxx> Subject: Re: [xsl] Resetting context to main document with "document()"? > Hi, > I was using the variable before, but it is not a nice solution: the problem > is that then I have the xml filename in the xsl, which is unpractical (what > if I change directories for xml / xsl). I tried also to set the variable to > "/" as shown below, but (MSXML) it outputs trash to the screen... > There is the obvious trick of passing the same name also as parameter, but > it is also not "elegant". I suppose there has to be a way to reset to the > MAIN parsed document without dirty tricks..... <xsl:variable name="doc" select="/"/> is THE one and in any case best solution to handle this problem. That MSXML outputs trash is not standard, it must come from your stylesheet. You can post your complete stylesheet here and we will have a look at it. Regards, Joerg 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] Resetting context to main, Markus Spath | Thread | Re: [xsl] Resetting context to main, Joerg Heinicke |
Re: [xsl] Contains(@href. '/') retu, NILESH PATEL | Date | [xsl] Re: uses for strSplit-to-Word, Dimitre Novatchev |
Month |