tags:

views:

145

answers:

2

There's an XSL that includes another XSL:

<xsl:include href="registered.xsl"/>

That included file has a list of nodes:

<g:registered>
  <node1/>
  <node2/>
</g:registered>

Documentation says that "the children of the <xsl:stylesheet> element in this document replace the element in the including document", so I would think that, given the include directive has worked, I can select g:registered nodes like if they always belonged to the inluding document:

select="document('')/xsi:schema/g:registered"

That returns an empty nodeset though.

However, this:

select="document('registered.xsl')/xsi:schema/g:registered"

does select what is required, but that, as I suppose, means opening the included file for the second time which doesn't seem nice to me.

So how do I select those includes without opening the file second time?

EDIT

Requested document structure: Included document:

<?xml version='1.0' encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:g="http://www.sample.com/ns"&gt;

<g:registered-templates>
  <SampleTemplate/>
  <WrongTemplate/>
</g:registered-templates>

<xsl:include href="Sample Template.xsl" />
<xsl:include href="Wrong Template.xsl" />

</xsl:stylesheet>

Including document:

<?xml version='1.0' encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:g="http://www.sample.com/ns"&gt;

<xsl:output method="text"/>

<xsl:include href="Label Registration.xsl"/>

<!-- How do I refer to just loaded inclusion without directing engine to the file again? -->
<xsl:variable name="template-names" select="document('Label Registration.xsl')/xsl:stylesheet/g:registered-templates"/>

<xsl:template match="Job">
  <xsl:for-each select="WorkItem">
    <xsl:apply-templates select="$template-names/*[local-name()=current()/@name]">
      <xsl:with-param name="context" select="." />
    </xsl:apply-templates>
  </xsl:for-each>
</xsl:template>


</xsl:stylesheet>
A: 

Selecting into your variable template-names queries the transformation source document - not your included stylesheet. If you want to refer to g:registered-templates you have to point to the file like a second source document.

EDIT

I'm not really sure. but it looks like you want to create an element according to the attribute value. In that case this post will be interesting for you.

<xsl:for-each select="WorkItem">
    <xsl:element name="{Type}" >
        <xsl:value-of select="current()/@name"/>
    </xsl:element>
</xsl:for-each>
Filburt
No, it's not that simple. I was doing this trick: http://www.biglist.com/lists/xsl-list/archives/200110/msg00753.html
GSerg
A: 

Ok, my understanding was wrong.

The document('') function opens the file anyway, so it has no advantages, performance-wise, over document('registered.xsl'). And since it queries the file, not the now-modified DOM model of current document, the result does not include my includes.

And it is not possible to query DOM model of the transformation template itself, as far as I'm concerned.

GSerg