'Apply numbering by excluding duplicate nodes independently of processor status

Concerning my Exclude duplicate nodes from when using the xsl:number theme, I resulted in the following code:

  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:exsl="http://exslt.org/common"
  xmlns:msxml="urn:schemas-microsoft-com:xslt"
  exclude-result-prefixes="exsl msxml"
  version="1.0">
 <xsl:output method="text" encoding="UTF-8"/>
 <xsl:key name="car" match="car" use="concat(., '|', ../@name)" />
  <xsl:template match="/cars">
   <xsl:variable name="temp">
    <xsl:for-each select="manufacturer">
     <manufacturer name="{@name}">
      <!-- copy only distinct values -->
      <xsl:copy-of select="car[count(. | key('car', concat(., '|', ../@name))[1]) = 1]"/>
     </manufacturer>
    </xsl:for-each>
   </xsl:variable>
   
  <!-- output -->
  <xsl:choose>
   <xsl:when test="function-available('exsl:node-set')">
   <xsl:for-each select="exsl:node-set($temp)/manufacturer">
    <xsl:text> Table_</xsl:text>
    <xsl:number count="manufacturer" format="A. ("/>
    <xsl:value-of select="@name"/>
    <xsl:text>)&#xA;</xsl:text>
     <xsl:for-each select="car">
      <xsl:number count="car" level="any" format="  1. "/>
      <xsl:value-of select="."/>
      <xsl:text>&#xA;</xsl:text>
     </xsl:for-each> 
    </xsl:for-each> 
   </xsl:when> 
   <xsl:when test="function-available('msxml:node-set')">  
    <xsl:for-each select="msxml:node-set($temp)/manufacturer">
    <xsl:text> Table_</xsl:text>
    <xsl:number count="manufacturer" format="A. ("/>
    <xsl:value-of select="@name"/>
    <xsl:text>)&#xA;</xsl:text>
     <xsl:for-each select="car">
      <xsl:number count="car" level="any" format="  1. "/>
      <xsl:value-of select="."/>
      <xsl:text>&#xA;</xsl:text>
     </xsl:for-each> 
   </xsl:for-each> 
   </xsl:when>
  </xsl:choose>
 </xsl:template>
</xsl:stylesheet>

I still have two questions: First : Can repetitions in xsl:choose eliminated, still using for-each syntax and not apply-template? Second: Is something more than 'exsl:node-set' and 'msxsl:node-set' that I am missing to check concerning processors? Code has been checked in three computers without necessarily knowing their processors status. Besides, code must work globally independent of user's processor which is unknown to the programmer. Thank you in advance.



Solution 1:[1]

Here is a way you can eliminate (most of) the code duplication:

XSLT 1.0

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:exsl="http://exslt.org/common"
xmlns:msxml="urn:schemas-microsoft-com:xslt">
<xsl:output method="text" encoding="UTF-8"/>

<xsl:key name="car" match="car" use="concat(., '|', ../@name)" />

<xsl:template match="/cars">
     <xsl:variable name="temp">
        <xsl:for-each select="manufacturer">
         <manufacturer name="{@name}">
            <!-- copy only distinct values -->
            <xsl:copy-of select="car[count(. | key('car', concat(., '|', ../@name))[1]) = 1]"/>
         </manufacturer>
        </xsl:for-each>
     </xsl:variable>
    <!-- output -->
    <xsl:choose>
        <xsl:when test="function-available('exsl:node-set')">
            <xsl:for-each select="exsl:node-set($temp)/manufacturer">
                <xsl:call-template name="output"/>
            </xsl:for-each> 
         </xsl:when>    
        <xsl:when test="function-available('msxml:node-set')">  
            <xsl:for-each select="msxml:node-set($temp)/manufacturer">
                <xsl:call-template name="output"/>
            </xsl:for-each> 
         </xsl:when>    
    </xsl:choose>
</xsl:template>

<xsl:template name="output">
    <xsl:text> Table_</xsl:text>
    <xsl:number count="manufacturer" format="A. ("/>
    <xsl:value-of select="@name"/>
    <xsl:text>)&#xA;</xsl:text>
    <xsl:for-each select="car">
        <xsl:number count="car" level="any" format="    1. "/>
        <xsl:value-of select="."/>
        <xsl:text>&#xA;</xsl:text>
    </xsl:for-each> 
</xsl:template>
    
</xsl:stylesheet>

I am afraid I did not understand your 2nd question.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 michael.hor257k