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
Conferences Close Tree View
+ Stylus Studio Feature Requests (1192)
+ Stylus Studio Technical Forum (14621)
+ Website Feedback (249)
- XSLT Help and Discussion (7625)
-> + How to add page number in to v... (2)
-> - XSL Grouping (7)
-> ->XSL Grouping
-> ->XSL Grouping
-> ->XSL Grouping
-> ->XSL Grouping
-> ->XSL Grouping
-> ->XSL Grouping
-> + Repeat images using FOR EACH l... (7)
-> + How to get File name (2)
-> + image and text on the same lin... (2)
-> + Create XSLT stylesheets for us... (2)
-> + Merge Multiple Files While Che... (2)
-> + xslt 3 level or multi level gr... (6)
-> + How to create xsl which will c... (2)
-> + xsl:variable and Result Tree F... (7)
-> - XSL-FO fo:table continued from... (1)
-> + XSLT Java issue (2)
-> + problem with hyperlink (4)
-> + substring-after function probl... (4)
-> + Xalan Processing (3)
-> + Memory utilization high with m... (2)
-> + check all parent node groups s... (2)
-> + CSV DOC to XML CONVERSION (11)
-> + XSLT: Ordered List (based on r... (4)
-> + XSLT Mapping - Issue (4)
-> + XSL following-sibling, how to ... (5)
-> + need xslt elements help (2)
-> + Dynamic generation of URL in X... (2)
-> + List Created from Section Navi... (2)
-> + xslt elements help (2)
-> + Map field if source is not nul... (3)
-> + XSLT group and sort whith gene... (4)
-> + Nested XML value (2)
-> + Specifying condition with coun... (4)
-> + xsl:function using found in er... (4)
-> + How to remove an unwanted spac... (2)
-> + Question about variable substi... (2)
-> + XSL for Comparing nodes and di... (4)
-> + External lookup list (8)
-> + XSL HTML output now needs to b... (2)
-> + Adding a new sub element to th... (4)
-> + How do I get rid of 'Tip' node... (9)
-> + Trying to dynamically create n... (2)
-> + Display XML link, using XSLT a... (9)
-> + calling templates based on ord... (2)
-> + How to add internal links usin... (4)
-> + How to call user defined java ... (3)
-> + XSLT and WebApps past and futu... (3)
-> + passing condition through java... (3)
-> + Apllying a template from withi... (4)
-> + Getting xsl element in javascr... (3)
-> + The document() function inside... (3)
-> + Footnote text move to para (2)
-> + XSL: multiple element come to ... (3)
-> + How to use following-sibling &... (2)
-> + How to use FOP 0.95 with Stylu... (4)
-> + Error during creating PDF from... (2)
-> + Help creating a comma delimite... (4)
-> + Selective Add using XSLT recur... (3)
-> + Help: convert without parent e... (2)
-> - Correct my substring function ... (1)
-> + Old xsl into reports (4)
-> + How to save xslt converted fil... (3)
-> + How to find non tagging text? (5)
-> + Help: Hex entity to Character... (6)
-> + EDI QUOTES MESSAGE NEED TO REP... (2)
-> + How to convert in multi level ... (4)
-> + Need some help with a styleshe... (3)
-> - Conditional Formattinf Formula... (1)
-> + Creating HTML Unordered LIsts.... (2)
-> + xslt params uknown number of i... (2)
-> + How to use fonts other than ba... (2)
-> - Converting existing HTML into ... (1)
-> + Help to tune up this XSLT (2)
-> + XSLT - is only converting the ... (2)
-> + XSLT Editor tab (4)
-> + Convert multiple files from XM... (2)
-> + how to use in select expressi... (2)
-> + Help needed in XSL transformat... (2)
-> + How to add a string with math ... (5)
-> + How to add a string with math ... (6)
-> - br element (1)
-> + Stylesheet directed terminatio... (2)
-> + Who can help me whit sum funct... (2)
-> + XSLT Works in Stylus Studio, n... (3)
-> - Filter by Attribute (1)
-> + Display x number of items whic... (6)
-> + MultiColumn Reporting (3)
-> + cant get namespace declaration... (3)
-> + Performance xsl:for each and n... (3)
-> + How to assign value to a XSLT ... (3)
-> + Select element value based on ... (2)
-> + Version 10 of Saxon? (8)
-> + How to get the value of a node... (5)
-> + Display Xpath using (4)
-> + XSLT to report (2)
-> + xslt help for a noobie (2)
-> + XSL-FO XML to PDF with XSLT (3)
-> + Using XSLT to transform XML to... (4)
-> + XSLT to sort a list alphabetic... (4)
-> + How to Get Colum Values based ... (2)
-> + non persisting predicate filte... (5)
-> + HTML to XSLT (2)
-> + extra carriage returns in "csv... (2)
-> + extra carriage returns in "csv... (3)
-- Previous [301-320] [321-340] [341-360] Next
+ XQuery Help and Discussion (2017)
+ Stylus Studio FAQs (159)
+ Stylus Studio Code Samples & Utilities (364)
+ Stylus Studio Announcements (113)
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>

   
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.