XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
karthick maniSubject: XSL Grouping
Author: karthick mani
Date: 27 Jul 2009 08:20 PM
Hi All,

I got a situation where i need to sort the xml elements in a snapshot and group them based on a section and subsection code. I can actually sort and group them, but i need to display a section and subsection heading only for the first element in that particular group. At the moment the section heading is displaying for all the elements.

Any help would be really helpful for me.

Thanks
KArthick.

Postnext
Tony LavinioSubject: XSL Grouping
Author: Tony Lavinio
Date: 31 Jul 2009 09:13 AM
Without seeing your code, it's hard to give advice, but:

Using the preceding-sibling:: axis, you can tell whether your
element is the first of a group or not, by comparing the name
of the previous element to the current element.

There is more information on grouping for XSLT 1.0 at
http://www.jenitennison.com/xslt/grouping/index.html

Hope this helps.

Postnext
karthick maniSubject: XSL Grouping
Author: karthick mani
Date: 02 Aug 2009 07:28 PM
Hi Tony,

Thanks for your reply. I am posting a bit of code which i have done to group the elements and sort them.

<xsl:template match="/">
<book style="IVS">
<xsl:for-each select="PublicationSnapshot/File[@type= 'cmp:ivs'] ">
<xsl:sort select="ivs:IVS/ivs:TherapeuticClasses/ivs:PrimaryTherapeuticClass/@TherapeuticClassCode" data-type="number" />
<xsl:sort select="ivs:IVS/ivs:IVSnames" />
<xsl:for-each-group select="ivs:IVS/ivs:TherapeuticClasses/ivs:PrimaryTherapeuticClass" group-by="@TherapeuticClassCode">
<xsl:choose>
<xsl:when test="not(contains(.,'-'))">
<section><xsl:attribute name="label"><xsl:value-of select = "@SectionCode" />.</xsl:attribute>
<title><xsl:value-of select="." /></title>
<placeobject span="1" error="0"><xsl:attribute name="ID">S<xsl:value-of select ="@SectionCode" /></xsl:attribute></placeobject>
<xsl:apply-templates select="../../../ivs:IVS" />
</section>
</xsl:when>
<xsl:otherwise>
<section>
<xsl:attribute name="label"><xsl:value-of select = "@SectionCode" />.</xsl:attribute>
<title><xsl:value-of select="substring-before(.,' -')" /></title>
<placeobject span="1" error="0"><xsl:attribute name="ID">S<xsl:value-of select ="@SectionCode" /></xsl:attribute></placeobject>
<section>
<xsl:attribute name="label">(<xsl:value-of select = "@SubsectionCodeAlpha" />)</xsl:attribute>
<title><xsl:value-of select="substring-after(.,'- ')" /></title>
<placeobject span="1" error="0"><xsl:attribute name="ID">S<xsl:value-of select ="@SectionCode" /><xsl:value-of select ="@SubsectionCodeAlpha" /></xsl:attribute></placeobject>
<xsl:apply-templates select="../../../ivs:IVS" />
</section>
</section>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each-group>
</xsl:for-each>
</book>
</xsl:template>

My desired output is like this

<book style="IVS">
<section label="1.">
<title>some text</title>
<placeobject ID="S1" span="1" error="0"/>
<section label="(a)">
<title>some text</title>
<placeobject ID="S1a" span="1" error="0"/>
<para style="text">text
<index prodnum="number"><level sort="text">text</level></index>
<inline style="text">Mtext</inline>
</para><para style="text"><emph type="bold"><font size="7.5pt">text</font></emph> Atropine sulfate 1&nnbsp;mg/mL, acepromazine (as maleate) 2&nnbsp;mg/mL; benzyl alcohol 0.01&nnbsp;mL/mL as preservative.</para>
<!--Next Element in the group-->
<para style="text">text
<index prodnum="number"><level sort="text">text</level></index>
<inline style="text">text</inline>
</para>
</section>
</section>

But my output at the moment is

<book style="text"><section label="1."><title>text</title><placeobject span="1" error="0" ID="S1"/><section label="(a)"><title>text</title><placeobject span="1" error="0" ID="S1a"/>
<para style="PROD">text<index prodnum="1070"><level>text</level></index><inline style="MANU">text</inline></para>
<para style="HD2"><emph type="bold"><font size="7.5pt">text</font></emph>text</para></para>
</section></section>
<!-- Next Element in the same group-->
<section label="1."><title>text</title><placeobject span="1" error="0" ID="S1"/><section label="(a)"><title>text</title><placeobject span="1" error="0" ID="S1a"/>
<para style="text">text<index prodnum="870"><level>text</level></index><inline style="MANU">text</inline></para>
</section></section>

It would be great if you could advice me how i can proceed from this.

Thanks
Karthick.

Postnext
Tony LavinioSubject: XSL Grouping
Author: Tony Lavinio
Date: 10 Aug 2009 10:55 AM
General-purpose XSLT questions are best asked on XSL-LIST run
by Mulberry Technologies.

But not seeing the input file makes it hard to see where your
transform is going wrong (you've shown us part of your transform,
a sample of good results and a sample of bad results) but the
pieces we need to see include the input.

Also, which XSLT engine are you using?

Postnext
karthick maniSubject: XSL Grouping
Author: karthick mani
Date: 10 Aug 2009 07:06 PM
Originally Posted: 10 Aug 2009 07:05 PM
Hi Tony,

I am using Saxon 8 for the transformation. My input will be like this

<PublicationSnapshot publicationName="" snapshotDate="" Url="">
<File type="cmp:ivs" name="IVS05039.xml" version="" Url="">
<IVS xmlns="" xmlns:cals="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="" ProductCode="5039" Issue="2009-02-01">
<IVSnames><IVSname type="listing">Baycox Cattle Coccidiocide</IVSname><IVSname type="simple">Baycox Cattle Coccidiocide</IVSname><IVSname type="file">BAYCOX CATTLE COCCIDIOCIDE IVS05039</IVSname></IVSnames>
<Company CompanyCode="171"><CompanyName>Bayer</CompanyName></Company>
<TherapeuticClasses><PrimaryTherapeuticClass TherapeuticClassCode = "130100" Section = "13A" SectionCode = "13" SubsectionCode = "1" SubsectionCodeAlpha = "a" SubclassCode = "" SubclassCodeAlpha = "" TherapeuticName = "Antibiotic and anti-infective supplements" FullTherapeuticName = "Nutrition and metabolism - Antibiotic and anti-infective supplements">Nutrition and metabolism - Antibiotic and anti-infective supplements</PrimaryTherapeuticClass>
</TherapeuticClasses>

<Composition><Para>Toltrazuril 50 g/L. For further information see Baycox Cattle Coccidiocide, Section 13a.</Para></Composition>
</IVS></File>

<File type="cmp:ivs" name="IVS04966.xml" version="1.0" alfrescoUrl="" nodeRef="versionStore://lightWeightVersionStore/72b753fe-f094-4892-a800-e2cd06867651" briefType="">

<IVS xmlns="" xmlns:cals="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="" ProductCode="4966" Issue="2009-02-01">
<IVSnames><IVSname type="listing">Abamectin Baymec LV</IVSname><IVSname type="simple">Abamectin Baymec LV</IVSname><IVSname type="file">ABAMECTIN BAYMEC LV IVS04966</IVSname></IVSnames>
<Company CompanyCode="171"><CompanyName>Bayer</CompanyName></Company>
<TherapeuticClasses><PrimaryTherapeuticClass TherapeuticClassCode = "150201" Section = "15B1" SectionCode = "15" SubsectionCode = "2" SubsectionCodeAlpha = "b" SubclassCode = "1" SubclassCodeAlpha = "i" TherapeuticName = "Large animals" FullTherapeuticName = "Parasiticides - External infestations - Large animals">Parasiticides - External infestations - Large animals</PrimaryTherapeuticClass>
</TherapeuticClasses>

<Composition><Para>Abamectin 2 g/L.</Para><Para>For further information see Abamectin Baymec LV, Section 15(a)(i).</Para></Composition>
</IVS></File>
<File type="cmp:ivs" name="IVS04378.xml" version="1.0" Url="" nodeRef="versionStore://lightWeightVersionStore/91ab0803-95d0-4e5e-a76e-ed9491bd9b3a" briefType="">

<IVS xmlns="" xmlns:cals="" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="" ProductCode="4378" Issue="2009-02-01">
<IVSnames><IVSname type="listing">Advocate for Cats</IVSname><IVSname type="simple">Advocate for Cats</IVSname><IVSname type="file">ADVOCATE FOR CATS IVS04378</IVSname></IVSnames>
<Company CompanyCode="171"><CompanyName>Bayer</CompanyName></Company>
<TherapeuticClasses><PrimaryTherapeuticClass TherapeuticClassCode = "150102" Section = "15A2" SectionCode = "15" SubsectionCode = "1" SubsectionCodeAlpha = "a" SubclassCode = "2" SubclassCodeAlpha = "ii" TherapeuticName = "Small animals" FullTherapeuticName = "Parasiticides - Internal infestations - Small animals">Parasiticides - Internal infestations - Small animals</PrimaryTherapeuticClass>
</TherapeuticClasses>

<Composition><Para>Imidacloprid 100 g/L, moxidectin 10 g/L.</Para><Para>For further information see Advocate for Cats, Section 15(b)(ii).</Para></Composition>
</IVS></File>
</PublicationSnapshot>

Thanks
Karthick.

Postnext
Tony LavinioSubject: XSL Grouping
Author: Tony Lavinio
Date: 11 Aug 2009 10:17 AM
We're looking at it, but note that empty namespace bindings are
illegal in XML. You cannot have xmlns="" or xmlns:cals="" and
expect the stylesheet to work.

Posttop
Tony LavinioSubject: XSL Grouping
Author: Tony Lavinio
Date: 11 Aug 2009 10:26 AM
You can use the preceding-sibling:: axis to check to see if this
is the first reference to that section. Save a copy of the
current value in a variable, and then do something like this:

<xsl:if test="preceding-sibling::section[@value != $saved]">
...display section...
<xsl:if>

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.