0

I am trying to get distinct values of shelf and add them to xml tree using node-set. I am trying to print the values of node-set using apply-templates. But I am doing something wrong. Kindly correct me. Thanks

  <xsl:template name="form_list">
        <xsl:for-each select="//library/section/@shelf[generate-id()= generate-id(key('distinct_shelfs',.)[1])]">
    
        <xsl:variable name="shelfs">
            <ml>
            <m><xsl:value-of select="."/></m>
            </ml>
        </xsl:variable> 
          
        </xsl:for-each>
    
    <xsl:variable name="Shelf_Set"><xsl:value-of select="exsl:node-set($shelfs)/ml"/></xsl:variable>
    
    </xsl:template>
    
    <xsl:call-template name="PrintShelfs"/> 
    
    <xsl:template name="PrintShelfs">
    
    <xsl:apply-templates select="$Shelf_Set" mode="m1"/>
    
    </xsl:template>
    
    <xsl:template match="ml" mode="m1" >
    
    <a><xsl:value-of select='.'/></a>
    
    </xsl:template>
mentor45
  • 17
  • 5
  • 2
    Please psot a [mcve], not snippets of code taken out of context.-- P.S. You seem to have a `xsl:call-template` instruction outside of any template - that would generate an error. – michael.hor257k Mar 29 '22 at 19:54

1 Answers1

0

The xsl:value-of instruction flattens a node-set to a single text node. I suspect you want simply

<xsl:variable name="Shelf_Set" select="exsl:node-set($shelfs)/ml"/>
Michael Kay
  • 156,231
  • 11
  • 92
  • 164
  • I made the suggested change, however i'm facing the error : Exception in thread "main" org.apache.xpath.XPathException: Can not convert #STRING to a NodeList! for this line of code ---> – mentor45 Mar 29 '22 at 20:43
  • Can't see any reason for that but if you're using Xalan, then you're using Java, which means there's no reason to still be using XSLT 1.0 which was superseded about 15 years ago. – Michael Kay Mar 29 '22 at 22:27
  • I am limited to use XSLT 1.0 , is there anything I can do? – mentor45 Mar 30 '22 at 05:47
  • As I say, I moved forward from XSLT 1.0 about 15 years ago, so I've forgotten all the crazy workarounds you had to use in that world. – Michael Kay Mar 30 '22 at 07:53
  • I changed the version of stylesheet to 2.0, perhaps there is some mistake in the code written. I am a newbie to this language and unable to proceed furthur. It would be nice if I can get some help – mentor45 Mar 30 '22 at 13:42
  • Setting the version attribute says that you would like to use XSLT 2.0 features; it doesn't magically turn your XSLT 1.0 processor into an XSLT 2.0 processor. – Michael Kay Mar 30 '22 at 13:47