This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: Carrying Namespaces through a XSL to XSL Transformation


I agree that disable-output-escaping should not be used in this case.  The
only defensible use of disable-output-escaping that I remember seeing is the
rendering of non-well-formed HTML in a browser (where the HTML markup is
actually content, not markup).

But there still is a problem here.  Namespace nodes found only in the source
tree are only copied to the result tree when nodes from the source tree are
copied.  If the stylesheet you're generating doesn't copy those nodes from
the source tree, the namespace nodes won't be copied either.  (When
namespace nodes are copied, you apparently can trust the resulting declared
prefixes to be the same as that of the source --
http://www.biglist.com/lists/xsl-list/archives/200010/msg00206.html)

A better solution to this problem can be found by temporarily copying an
element in the source tree for which all the desired namespace declarations
are in scope.  Within that copied element, you can then produce the rest of
your stylesheet.  The final step, of course, is to extract the produced
stylesheet from this temporary root element.  This requires use of the
node-set function, or another XSLT transformation.  (Incidentally, I seem to
remember finding that the node-set solution was extremely slower, when using
SAXON and a large stylesheet, than serializing, parsing, and doing another
transformation, but that's another issue, particularly interesting with
regard to v1.1 eliminating the need for the node-set function
altogether--maybe Mike Kay can address this, but I continue to digress...)

Here's an example that assumes all required namespace declarations will be
found on the root element of the source tree (you can experiment with the
three template rules provided by changing the modes):

<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:saxon="http://icl.com/saxon"
  xmlns:out="http://xyzfind.com/dummy">

  <xsl:namespace-alias stylesheet-prefix="out"
                       result-prefix="xsl"/>

  <!-- this one creates a temporary tree to
       propagate source tree namespace declarations -->
  <xsl:template match="/xsl:stylesheet">
    <xsl:variable name="tempTree">
      <xsl:copy>
        <out:stylesheet version="1.0">
          <!-- produce the stylesheet -->
        </out:stylesheet>
      </xsl:copy>
    </xsl:variable>
    <xsl:copy-of select="saxon:node-set($tempTree)/*/*"/>
  </xsl:template>

  <!-- this version works, but
       requires another transformation -->
  <xsl:template match="/xsl:stylesheet"
                mode="requiresSubsequentTransformation">
    <xsl:copy>
      <out:stylesheet version="1.0">
        <!-- produce the stylesheet -->
      </out:stylesheet>
    </xsl:copy>
  </xsl:template>

  <!-- this is probably what you tried that didn't work -->
  <xsl:template match="/xsl:stylesheet"
                mode="failedAttempt">
    <out:stylesheet version="1.0">
      <!-- produce the stylesheet -->
    </out:stylesheet>
  </xsl:template>

</xsl:stylesheet>


Here's the *source* document:

<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:a="http://www.namespace.we.want.to.propagate">

  <xsl:template match="a:stuff">
    <!-- stuff -->
  </xsl:template>

</xsl:stylesheet>


Here's the (desired) result:

<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:a="http://www.namespace.we.want.to.propagate"/>


But this approach only works when you know where the namespace declarations
are (at the root element of the source document, in this case).  It breaks
down when you move the namespace declarations in the source around like so:

<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:template match="a:stuff"
xmlns:a="http://www.namespace.we.wanted.to.propagate">
    <!-- stuff -->
  </xsl:template>

</xsl:stylesheet>


Again, it will only work if the nodes for which the desired namespaces are
in scope are copied to the result.

Thus, this isn't a perfect solution.  For now, I'm guessing the solution is
to copy as much as possible (as opposed to using literal result elements)
and test the result to make sure it worked (yuck!)  It's been a while since
I've implemented real applications of this, so if I'm missing something, I'd
love to hear it!  I do feel that I'm missing something...

Evan Lenz
elenz@xyzfind.com
http://www.xyzfind.com
XYZFind -- Repository, Search, and Query for XML
Download our free beta software: http://www.xyzfind.com/beta


-----Original Message-----
From: owner-xsl-list@lists.mulberrytech.com
[mailto:owner-xsl-list@lists.mulberrytech.com]On Behalf Of Julian F.
Reschke
Sent: Thursday, December 28, 2000 3:32 PM
To: xsl-list@lists.mulberrytech.com
Cc: chadsm@mitre.org
Subject: RE: [xsl] Carrying Namespaces through a XSL to XSL
Transformation


Sorry,

but what problem is this intended to solve?

(Almost) every time I see disable-output-escaping and xsl:text being used to
generate XML, there's something wrong with the design of the XSLT code...

Julian

> -----Original Message-----
> From: owner-xsl-list@lists.mulberrytech.com
> [mailto:owner-xsl-list@lists.mulberrytech.com]On Behalf Of Kevin
> McCarthy
> Sent: Wednesday, December 27, 2000 7:39 PM
> To: xsl-list@lists.mulberrytech.com
> Cc: chadsm@mitre.org
> Subject: Re: [xsl] Carrying Namespaces through a XSL to XSL
> Transformation
>
>
> Chad,
>
> Here is a template that I have used in the past, using MSXML3.
> This successfully outputs multiple namespace references in the resulting
> XSLT.
> I am using parameters in the below example to define on of my
> namespaces and
> schema locations.
>
> Good luck,
> -Kevin
>
>
>
> <!--
>  renderXSLStylesheetStart:
>   renders the opening xsl:stylesheet tag and attrs
> -->
> <xsl:template name="renderXSLStylesheetStart">
> <xsl:text disable-output-escaping="yes">&#60;&#63;xml
> version="1.0"&#63;&#62;</xsl:text>
> <xsl:text disable-output-escaping="yes">
> &#60;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> version="1.0"</xsl:text>
>   xmlns:s="urn:schemas-microsoft-com:xml-data"
>   xmlns:dt="urn:schemas-microsoft-com:datatypes"
>   xmlns:<xsl:value-of select="$ns"
> />="x-schema:http://localhost/schema/<xsl:value-of select="$name"
> />Schema.xml"
>   xmlns:editA="x-schema:http://localhost/schema/EditAttributes.xml" &#62;
> </xsl:text>
> </xsl:template>
>
> -----Original Message-----
> From: Smith, Chad <chadsm@mitre.org>
> To: 'xsl-list@lists.mulberrytech.com' <xsl-list@lists.mulberrytech.com>
> Date: Wednesday, December 27, 2000 10:30 AM
> Subject: [xsl] Carrying Namespaces through a XSL to XSL Transformation
>
>
> >> Because of the inability to convert XPath strings to XPath
> nodesets, I am
> >> forced to perform XSL to XSL Transformations.  these
> transformations have
> >> worked out well with a single exception: I cannot migrate more than one
> >> namespace to the resulting XSLT file.  This is a problem
> because I would
> >> like for the resulting XSLT to utilize some form of embedded
> script, but
> >> since I am using Xalan, this requires two additional namespaces.
> >>
> >> I am currently using 'xsl:namespace-alias' to carry over the actual XSL
> >> namespace, however multiple uses of this tag with different
> properties do
> >> not migrate additional namespaces but only attempt to overwrite the
> first.
> >>
> >> Any ideas?
> >
> > XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> >
> >
>
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]