Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Grouping/Sorting Problem

From: SarahLund@-----------.---------.---
To: NULL
Date: 10/12/2006 1:50:00 PM

Thank you so much - this gets me well on my way!

Sarah

"Dimitre Novatchev" wrote:

> This is a wellknown problem and it has a wellknown solution.
> 
> As Michelle has explained, it is trivial to solve, given one can use the 
> xxx:node-set() extension function.
> 
> I assume that you do not want to use any extension functions.
> 
> In this case, here's one solution:
> 
> This XSLT transformation:
> 
> <xsl:stylesheet version="1.0"
>  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>  <xsl:output omit-xml-declaration="yes" indent="yes"/>
>  <xsl:strip-space elements="*"/>
> 
>  <xsl:key name="kModByID" match="Module | Perf_Module"
>   use="@nID"/>
> 
>  <xsl:template match="/">
>   <html>
>     <xsl:for-each select=
>        "/*/*/*/*/Module
>           [generate-id()
>           =
>            generate-id(key('kModByID',@nID)[1])
>           ]"
>     >
>      <table>
>       <xsl:for-each select=
>        "(
>          /*/*/*/*/Module
>        |
>         /*/*/*/*/*/Perf_Module
>         )
>         [@nID = current()/@nID] /*
>         ">
>           <xsl:sort select="@displayOrder" data-type="number"/>
> 
>           <xsl:variable name="vID" select="../@nID"/>
> 
>           <xsl:if test="position() mod 2 = 1">
>            <tr>
>              <td><xsl:value-of select="@name"/></td>
>              <td>
>                <xsl:call-template name="sortedNth">
>                  <xsl:with-param name="pId" select="$vID"/>
>                  <xsl:with-param name="pPos"
>                   select="position()+1"/>
>                </xsl:call-template>
>              </td>
>            </tr>
>           </xsl:if>
> 
>        </xsl:for-each>
>      </table>
>     </xsl:for-each>
>   </html>
>  </xsl:template>
> 
>  <xsl:template name="sortedNth">
>    <xsl:param name="pId" select="0"/>
>    <xsl:param name="pPos" select="0"/>
> 
>    <xsl:if test="$pPos > 0 and $pId > 0">
>      <xsl:for-each select=
>        "/*/*/*/*/*[@nID = $pId]/Category
>        |
>         /*/*/*/*/*/*[@nID = $pId]/Perf_Category
>         "
>        >
>        <xsl:sort select="@displayOrder" data-type="number"/>
> 
>        <xsl:if test="position() = $pPos">
>          <xsl:copy-of select="string(@name)"/>
>        </xsl:if>
>      </xsl:for-each>
>    </xsl:if>
> 
>  </xsl:template>
> </xsl:stylesheet>
> 
> 
> when applied on the origianl source xml document:
> 
> <Products>
>  <Begin_Product nID="2002421">
>   <Selection>
>    <Selection_Number>1</Selection_Number>
>    <Configuration_Data>
>     <Module displayOrder="10" nID="4656" name="Base Unit Module">
>      <Category displayOrder="10" nID="21" name="Unit"/>
>      <Category displayOrder="50" nID="43" name="Frame"/>
>      <Category displayOrder="20" nID="67" name="Unit Roof"/>
>     </Module>
>     <Module displayOrder="20" nID="4658" name="Fan Module">
>      <Category displayOrder="10" nID="96" name="Fan Module"/>
>      <Category displayOrder="20" nID="63" name="Fan Size"/>
>     </Module>
>    </Configuration_Data>
>    <Performance_Data>
>     <Perf_Data>
>      <Perf_Module nID="4656" name="Base Unit Module">
>       <Perf_Category displayOrder="30" nID="10" name="Unit Airflow"/>
>       <Perf_Category displayOrder="10" nID="91" name="Elevation"/>
>       <Perf_Category displayOrder="40" nID="13" name="Htg"/>
>      </Perf_Module>
>      <Perf_Module nID="4658" name="Fan Module">
>       <Perf_Category displayOrder="20" nID="23" name="Airflow"/>
>       <Perf_Category displayOrder="90" nID="30" name="AbsPower"/>
>      </Perf_Module>
>     </Perf_Data>
>    </Performance_Data>
>   </Selection>
>  </Begin_Product>
> </Products>
> 
> produces the wanted result:
> 
> <html>
>  <table>
>   <tr>
>    <td>Unit</td>
>    <td>Elevation</td>
>   </tr>
>   <tr>
>    <td>Unit Roof</td>
>    <td>Unit Airflow</td>
>   </tr>
>   <tr>
>    <td>Htg</td>
>    <td>Frame</td>
>   </tr>
>  </table>
>  <table>
>   <tr>
>    <td>Fan Module</td>
>    <td>Fan Size</td>
>   </tr>
>   <tr>
>    <td>Airflow</td>
>    <td>AbsPower</td>
>   </tr>
>  </table>
> </html>
> 
> Cheers,
> Dimitre Novatchev
> 
> 
> 
> "Sarah_Lund" <SarahLund@d...> wrote in message 
> news:2FB78E50-070F-4ADA-9F4F-1F50502E1D1D@m......
> > Thank you for your understanding and I will try to clarify.
> >
> > I need to create a table For Each Selection in the xml file.
> > Then in each table For Each
> > Configuration_Data/Module/@nID=Performance_Data/Perf_Data/Perf_Module/@nID, 
> > I
> > need to SORT on
> > /Products/Begin_Product/Selection/Configuration_Data/Module/Category/@displayOrder
> > and
> > /Products/Begin_Product/Selection/Performance_Data/Perf_Data/Perf_Module/Perf_Category/@displayOrder
> > (together as one list). And then put the
> > /Products/Begin_Product/Selection/Configuration_Data/Module/Category/@name
> > and
> > /Products/Begin_Product/Selection/Performance_Data/Perf_Data/Perf_Module/Perf_Category/@name
> > values in order horizontally in multiple columns with each item in an
> > individual table cell.
> >
> > Thank you in advance for trying to understand my explanation.
> > Sarah
> >
> > The xml is below in the event you don't have it from before.
> > <Products>
> > <Begin_Product nID="2002421">
> > <Selection>
> > <Selection_Number>1</Selection_Number>
> > <Configuration_Data>
> > <Module displayOrder="10" nID="4656" name="Base Unit Module">
> > <Category displayOrder="10" nID="21" name="Unit"/>
> > <Category displayOrder="50" nID="43" name="Frame"/>
> > <Category displayOrder="20" nID="67" name="Unit Roof"/>
> > </Module>
> > <Module displayOrder="20" nID="4658" name="Fan Module">
> > <Category displayOrder="10" nID="96" name="Fan Module"/>
> > <Category displayOrder="20" nID="63" name="Fan Size"/>
> > </Module>
> > </Configuration_Data>
> > <Performance_Data>
> > <Perf_Data>
> > <Perf_Module nID="4656" name="Base Unit Module">
> > <Perf_Category displayOrder="30" nID="10" name="Unit Airflow"/>
> > <Perf_Category displayOrder="10" nID="91" name="Elevation"/>
> > <Perf_Category displayOrder="40" nID="13" name="Htg"/>
> > </Perf_Module>
> > </Perf_Module nID="4658" name="Fan Module">
> > <Perf_Category displayOrder="20" nID="23" name="Airflow"/>
> > <Perf_Category displayOrder="90" nID="30" name="AbsPower"/>
> > </Perf_Module>
> > </Perf_Data>
> > </Performance_Data>
> > </Selection>
> > </Begin_Product>
> > </Products>
> > 
> 
> 
> 


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent