Avatar of deleyd
Flag for United States of America

asked on 

Extract Last Node in Variable

<xsl:stylesheet version="1.0"
  <xsl:output method="xml"/>

  <xsl:template match="/">
      <xsl:variable name="v">
        <xsl:call-template name="HelloWorld"/>
      <xsl:variable name="x" select="v/*[position() != last()]"/>
      <xsl:copy-of select="$x"/>          

  <xsl:template name="HelloWorld">
    <p>Hello world!</p>

Open in new window

I'm trying to strip off the "5" which is appended to the end. My desired output is
<?xml version="1.0" encoding="utf-8"?><html><body><p>Hello world!</p></body></html>

Open in new window

and I would also like to get that "5" into a variable.

The debugger shows variable v is:

Debugger outputand variable x is empty (my select isn't working).

Update: I see I forgot the $. Change that line to:
<xsl:variable name="x" select="$v/*[position() != last()]"/>

Open in new window

and now I get an exception which says, "To use a result tree fragment in a path expression, first convert it to a node-set using the msxsl:node-set()". Great. (I actually used to know this stuff a few years ago! I've forgotten it all! How do I convert this to a node-set?)

Avatar of undefined
Last Comment
Gertone (Geert Bormans)

8/22/2022 - Mon