xsl-list
[Top] [All Lists]

Re: [xsl] Applying Attributes with Grouping Method

2007-03-21 05:48:55

I'm tired of banging my head against the wall.

Keep doing it, you get used to it eventually!

Now, I can get the name attributes grouped using the Muenchian Method
in

you are using saxon8 so XSLT2 so you don't need Muenchian grouping,
once I'd made your input example well formed, it's just a call to
xsl:for-each-group:

<connection>
        <conn name="P21" part="W1123">
                <property name="s_des" val="Part_A"/>
        </conn>
        <conn name="P22" part="W1123">
                <property name="s_des" val="Part_A"/>
        </conn>
        <conn name="P23" part="W1123">
                <property name="s_des" val="Part_A"/>
        </conn>
        <conn name="J31" part="W1144">
                <property name="s_des" val="Part_B"/>
        </conn>
        <conn name="J32" part="W1145">
                <property name="s_des" val="Part_C"/>
        </conn>
</connection>




<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
  <xsl:output indent="yes"/>

  <xsl:template match="connection">
    <report>
      <xsl:for-each-group select="conn" 
group-by="property[(_at_)name='s_des']/@val">
        <item part="{(_at_)part}" 
        uantity="{count(current-group())}"
        val="{current-grouping-key()}"
        name="{current-group()/@name}"/> 
      </xsl:for-each-group>
    </report>
  </xsl:template>

</xsl:stylesheet>


$ saxon8 connection.xml  connection.xsl 
<?xml version="1.0" encoding="UTF-8"?>
<report>
   <item part="W1123" uantity="3" val="Part_A" name="P21 P22 P23"/>
   <item part="W1144" uantity="1" val="Part_B" name="J31"/>
   <item part="W1145" uantity="1" val="Part_C" name="J32"/>
</report>


David

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>