Why I get fragment node instead a node set in this template?

Hi everyone!

I'm trying to do a XSL 1.0 to transform XSD but I hava a problem initializing a variable.

CONTEXT

Well, here it's the code where I initialize the variable:

<xsl:variable name="gNS">
  <xsl:call-template name="get_global_NS">
    <xsl:with-param name="type" select="$main_type"/>
      <xsl:with-param name="class_type" select="$class"/>
  </xsl:call-template>
</xsl:variable>

And now, the template get_global_NScode:

<xsl:template name="get_global_NS">
  <xsl:param name="type"/>
  <xsl:param name="class_type"/>
  <xsl:variable name="prefix" select="substring-before($type,':')"/>
  <xsl:choose>
    <xsl:when test="$prefix = 'b'">
      <xsl:value-of select="$ns_base"/>
    </xsl:when>
    <xsl:otherwise>
      <xsl:choose>
        <xsl:when test="$prefix = 'c'">
          <xsl:value-of select="$ns_conceptuels"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:choose>
            <xsl:when test="$prefix = 'd' and contains($class_type,'A5')">
              <xsl:value-of select="$ns_dom_a5"/>
            </xsl:when>
            <xsl:otherwise>
              <xsl:value-of select="$ns_dom_vega"/>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

The variables $ns_base, $ns_conceptuels, $ns_dom_a5 and $ns_dom_vega are defined as global variables. All of them are initialized with a document node. The following line is the initialzation of ns_base:

<xsl:variable name="ns_base" select="document('../Types/Base.xsd')"/>

PROBLEM

Well, when I try to use gNSvariable to select a node when I call other named-template I have the problem. It is a node-fragment instead a node.

Here, the trouble spot:

<xsl:call-template name="write_type">
<!-- 
  This temaplate process a xs:simpleType or xs:complexType named like the mainType.
  Due to the main_type has a namespace prefix, I get the actual name calling 
  substring-after() function
-->
  <xsl:with-param name="type_elem" select="$gNS//*[@name=substring-after($main_type,':')]"/>
  <xsl:with-param name="fed_type" select="$type"/>
</xsl:call-template>

The problem is just in this select: select="$gNS//*[@name=substring-after($main_type,':')]". $gNS is just a node fragment :(

Thanks in advance! And if someone needs more information, ask me for it!

Answers


Well any time in XSLT 1.0 you populate a variable other than with the select attribute you get a result tree fragment. If you then want to do XPath selection on nodes in the result tree fragment you first need to use an extension function to convert the result tree fragment to a node set. Most XSLT 1.0 processors support exslt:node-set (http://www.exslt.org/exsl/functions/node-set/) or similar. So for your code that means you put xmlns:exsl="http://exslt.org/common" on your xsl:stylesheet element and then when you want to do XPath selection on a variable with a result tree fragment you use exsl:node-set($var)/foo/bar i.e. select="exsl:node-set($gNS)//*[@name=substring-after($main_type,':')]".


Need Your Help

InvalidOperationException when hiding/showing columns in a WPF DataGrid

c# .net wpf datagrid

I have a DataGrid and I want the user to be able to show/hide columns on it.

MVC3 partial view for edit pop-up

asp.net-mvc-3 partial-views edit

I am writing a MVC3 project. Right now I have a table which has column with Data as actionLinks as:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.