<xsl:apply-templates> not returning a node-set???

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Blaise Garant

    <xsl:apply-templates> not returning a node-set???

    Hi

    I've made a stylesheet to transform my data into XSL-FO. This
    stylesheet used to work with MSXSL 4.0 but I've got some issues in
    ..NET. First, I changed removed all the "node-set()" function since
    they're not used anymore. But now, I used an <xsl:apply-templates/>
    and for some reason, it works in some situation but not in others. I
    didn't put the whole XSL file since it's quite big. Here's the part
    that bugs

    <xsl:template match="Status">
    <xsl:variable name="Position" >
    <xsl:number count="/Cahier/*[name()!='Inform ation']"/>
    </xsl:variable>
    <xsl:element name="fo:block" >
    <xsl:if test="not($Posi tion=1 and position()=1)">
    <xsl:attribut e name="break-before">page</xsl:attribute>
    </xsl:if>
    <fo:marker marker-class-name="Status-Number">Status <xsl:value-of
    select="../Status/@ID"/></fo:marker>
    <fo:marker marker-class-name="Status-Name">Allo</fo:marker>
    <xsl:apply-templates/>
    </xsl:element>
    </xsl:template>

    And here's a sample of the XML going throught it:

    <Cahier>
    <Actives>
    <Status ID="1">
    <Name>Actif</Name>
    <Participant>
    <NAS>12345678 9</NAS>
    <Name>
    <Surname>John </Surname>
    <Given>Doe</Given>
    </Name>
    <DOB>1944-09-23T12:00:00</DOB>
    <Province />
    <SpouseName>
    <Surname>Johann e</Surname>
    <Given>Doe</Given>
    </SpouseName>
    <Sexe>1</Sexe>
    <DOBduConjoin t />
    </Participant>
    <Participant>
    ....
    </Participant>
    </Status>
    </Actives>
    </Cahier>

    So the "apply-templates" tag continu the process to the <Name> and
    <Participant> tags but for some reason, I get an "The expression
    passed to this method should result in a NodeSet." exception. I
    thought it might be my templates for the above mention tags but I
    folow my XmlReader step by step and it really stop right there and I
    don't see what's wrong with my XSLT. And both XML and XSLT file are
    properly formed. Anybody got an idea?

    Thx
    Blaise Garant
  • Oleg Tkachenko [MVP]

    #2
    Re: &lt;xsl:appl y-templates&gt; not returning a node-set???

    Blaise Garant wrote:
    [color=blue]
    > I've made a stylesheet to transform my data into XSL-FO. This
    > stylesheet used to work with MSXSL 4.0 but I've got some issues in
    > .NET. First, I changed removed all the "node-set()" function since
    > they're not used anymore.[/color]

    Could you elaborate this point? There is no any difference between MSXML
    and .NET with regard to node-set() extension function. If you use in in
    MSML stylesheet, you have to continue use it in .NET.
    [color=blue]
    > So the "apply-templates" tag continu the process to the <Name> and
    > <Participant> tags but for some reason, I get an "The expression
    > passed to this method should result in a NodeSet." exception.[/color]

    I don't believe <xsl:apply-templates/> instruction may cause this
    exception. Chances are it's connected with node-set() function you have
    removed - it converts a result tree fragment to a nodeset.
    --
    Oleg Tkachenko [XML MVP, XmlInsider]

    Comment

    • Blaise Garant

      #3
      Re: &lt;xsl:appl y-templates&gt; not returning a node-set???

      Thx for your fast answer Oleg,

      "Oleg Tkachenko [MVP]" <oleg@no_!spam! _please!tkachen ko.com> wrote in message news:<uazEN0aHE HA.2612@TK2MSFT NGP09.phx.gbl>. ..[color=blue]
      > Blaise Garant wrote:
      >[color=green]
      > > I've made a stylesheet to transform my data into XSL-FO. This
      > > stylesheet used to work with MSXSL 4.0 but I've got some issues in
      > > .NET. First, I changed removed all the "node-set()" function since
      > > they're not used anymore.[/color]
      >
      > Could you elaborate this point? There is no any difference between MSXML
      > and .NET with regard to node-set() extension function. If you use in in
      > MSML stylesheet, you have to continue use it in .NET.[/color]

      Well, it doesn't seem like it. See, in my XML sample, <Cahier> is in
      fact a childnode to <Booklet>. So at the begining of the stylesheet I
      made a global variable: <xsl:variable name="MemberInf o"
      select="/Booklet/Cahier"/>. Now if I use <xsl:value-of
      select="$Member Info/Actives/Status/Participant/NAS"> I get the value
      of the NAS node of the first Participant node, just like I should
      expect (in that sample, 123456789). Now this was impossible with
      MSXML, I need the node-set() function to do this. Also, now as soon as
      I use node-set(), I get a "Function 'msxsl:node-set()' has failed."
      exception.
      [color=blue]
      >[color=green]
      > > So the "apply-templates" tag continu the process to the <Name> and
      > > <Participant> tags but for some reason, I get an "The expression
      > > passed to this method should result in a NodeSet." exception.[/color]
      >
      > I don't believe <xsl:apply-templates/> instruction may cause this
      > exception. Chances are it's connected with node-set() function you have
      > removed - it converts a result tree fragment to a nodeset.[/color]
      Ok, you're right, they are partly connected. I use my XMLReader to
      read the output line by line. Everything goes well up to that point.
      I've got a template for a match with a Participant node, starting with
      variables. So I put a empty node just for a test and so, it stop just
      after it so you're right, <xsl:apply-templates/> is not the problem.
      Here's another XSLT sample:

      -------------XSLT---------------
      <xsl:template match="Particip ant">
      <xsl:variable name="TemplateT ype">
      <xsl:value-of select="name(pa rent::*/parent::*)"/>
      </xsl:variable>

      <test><xsl:valu e-of
      select="msxsl:n ode-set($TemplateTy pe)"/></test>

      <xsl:variable name="BiggerCol ">
      <xsl:variable name="Sub">
      <xsl:for-each
      select="$Layout Info/Booklet_Definit ion/child::*[name()=$Templat eType]/Member/Column">
      <xsl:element name="Column">
      <xsl:element name="ColumnLen "><xsl:valu e-of
      select="count(c hild::Element)"/></xsl:element>
      <xsl:element name="Position" ><xsl:value-of
      select="positio n()"/></xsl:element>
      </xsl:element>
      </xsl:for-each>
      </xsl:variable>
      .....
      </xsl:template>
      ----------------------------
      So it seems the program stoped while doing the BiggerCol variable node
      (before I put the <test> node). With the <test> node the program bugs
      at the <xsl:value-of> node. $TemplateType should contain the value
      "Actives" but the call <xsl:value-of select="$Templa teType" seems now
      to be waiting for a node-set! So as you see, I've try <xsl:value-fo
      select="msxsl:n ode-set($TemplateTy pe)/> But I get the same error
      (curriously, not the "node-set() failed" exception).

      Got an idea?
      Blaise

      Comment

      • Oleg Tkachenko [MVP]

        #4
        Re: &lt;xsl:appl y-templates&gt; not returning a node-set???

        Blaise Garant wrote:
        [color=blue]
        > expect (in that sample, 123456789). Now this was impossible with
        > MSXML, I need the node-set() function to do this.[/color]
        I don't think so if you are talking about MSXML3 and MSXML4. They are as
        good as .NET. You don't need node-set() extension function to navigate
        over nodes-set bound variable. You need it to navigate over
        result-tree-fragment bound variable though (xsl:variable with no select
        attribute).
        [color=blue]
        > -------------XSLT---------------
        > <xsl:template match="Particip ant">
        > <xsl:variable name="TemplateT ype">
        > <xsl:value-of select="name(pa rent::*/parent::*)"/>
        > </xsl:variable>
        >
        > <test><xsl:valu e-of
        > select="msxsl:n ode-set($TemplateTy pe)"/></test>
        >
        > <xsl:variable name="BiggerCol ">
        > <xsl:variable name="Sub">
        > <xsl:for-each
        > select="$Layout Info/Booklet_Definit ion/child::*[name()=$Templat eType]/Member/Column">
        > <xsl:element name="Column">
        > <xsl:element name="ColumnLen "><xsl:valu e-of
        > select="count(c hild::Element)"/></xsl:element>
        > <xsl:element name="Position" ><xsl:value-of
        > select="positio n()"/></xsl:element>
        > </xsl:element>
        > </xsl:for-each>
        > </xsl:variable>
        > ....
        > </xsl:template>
        > ----------------------------
        > So it seems the program stoped while doing the BiggerCol variable node
        > (before I put the <test> node). With the <test> node the program bugs
        > at the <xsl:value-of> node. $TemplateType should contain the value
        > "Actives" but the call <xsl:value-of select="$Templa teType" seems now
        > to be waiting for a node-set! So as you see, I've try <xsl:value-fo
        > select="msxsl:n ode-set($TemplateTy pe)/> But I get the same error
        > (curriously, not the "node-set() failed" exception).
        >
        > Got an idea?[/color]

        <xsl:value-of> doesn't care about argument type. It can outbut both
        node-set and rtf. What kind of error do you get?

        --
        Oleg Tkachenko [XML MVP, XmlInsider]

        Comment

        Working...