 |
| XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

August 30th, 2010, 07:18 AM
|
|
Registered User
|
|
Join Date: Aug 2010
Posts: 6
Thanks: 2
Thanked 0 Times in 0 Posts
|
|
grouping for xslt report
Dear All,
I am using apache FOP for xsl report generation, but I am not able to do the grouping for the given xml.
<?xml version = '1.0'?>
<ROWSET>
<ROW num='1'>
<COL1>I</COL1>
<COL2>passwordOrder</COL2><COL3>N</COL3>
<COL4> </COL4><COL5>1</COL5>
<COL6>CcsUserPasswordHistory</COL6>
<COL7>SHREE</COL7><COL8>2010-08-25 06:57:18.062</COL8>
<COL9>1026877</COL9>
<COL10>CcsUserPasswordHistory</COL10><COL11>I</COL11>
<COL12>InstallationParameter</COL12>
<COL13>VIEW</COL13>
</ROW>
<ROW num='2'>
<COL1>I</COL1>
<COL2>seqUserPasswordId</COL2>
<COL3>N</COL3><COL4> </COL4><COL5>1441</COL5>
<COL6>CcsUserPasswordHistory</COL6>
<COL7>SHREE</COL7>
<COL8>2010-08-25 06:57:18.062</COL8>
<COL9>1026877</COL9>
<COL10>CcsUserPasswordHistory</COL10>
<COL11>I</COL11>
<COL12>InstallationParameter</COL12><COL13>VIEW</COL13>
</ROW>
<ROW num='3'>
<COL1>I</COL1>
<COL2>uuid</COL2><COL3>A</COL3><COL4> </COL4><COL5>6d7da8c0-6590-4db3-b478-cf058462b2f1</COL5>
<COL6>CcsUserPasswordHistory</COL6><COL7>SHREE</COL7><COL8>2010-08-25 06:57:18.062</COL8>
<COL9>1026877</COL9><COL10>CcsUserPasswordHistory</COL10><COL11>I</COL11>
<COL12>InstallationParameter</COL12><COL13>VIEW</COL13>
</ROW>
<ROW num='4'>
<COL1>I</COL1>
<COL2>userId</COL2><COL3>A</COL3><COL4> </COL4><COL5>SHREE</COL5><COL6>CcsUserPasswordHistory</COL6>
<COL7>SHREE</COL7><COL8>2010-08-25 06:57:18.062</COL8><COL9>1026877</COL9>
<COL10>CcsUserPasswordHistory</COL10><COL11>I</COL11><COL12>InstallationParameter</COL12>
<COL13>VIEW</COL13>
</ROW>
<ROW num='5'>
<COL1>U</COL1><COL2>pwdChangeAtLogOn</COL2><COL3>A</COL3>
<COL4>1</COL4><COL5>0</COL5><COL6>CcsUsersM</COL6><COL7>SHREE</COL7>
<COL8>2010-08-25 06:57:18.062</COL8><COL9>1026877</COL9><COL10>CcsUsersM</COL10><COL11>U</COL11>
<COL12>InstallationParameter</COL12><COL13>VIEW</COL13>
</ROW>
<ROW num='6'>
<COL1>U</COL1>
<COL2>password</COL2><COL3>A</COL3><COL4>*****</COL4><COL5>*****</COL5><COL6>CcsUsersM</COL6>
<COL7>SHREE</COL7><COL8>2010-08-25 06:57:18.062</COL8><COL9>1026877</COL9><COL10>CcsUsersM</COL10>
<COL11>U</COL11><COL12>InstallationParameter</COL12><COL13>VIEW</COL13>
</ROW>
<ROWSET>
and xslt for the above xml is following:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" exclude-result-prefixes="fo">
<xsl:output method="xml" version="1.0" omit-xml-declaration="no" indent="yes"/>
<xsl:param name="auditTitle" select="'agEncoder Audit Trail Report'"/>
<xsl:param name="fieldName" select="'Field Name'"/>
<xsl:param name="functionType" select="'Function Type'"/>
<xsl:param name="operationType" select="'Operation Type'"/>
<xsl:param name="oldVal" select="'Old Value'"/>
<xsl:param name="newVal" select="'New Value'"/>
<xsl:param name="entityName" select="'Entity Name'"/>
<xsl:param name="transactionId" select="'Transaction ID'"/>
<xsl:param name="modifiedBy" select="'Modified By'"/>
<xsl:param name="modifiedDate" select="'Modified Date'"/>
<xsl:param name="useFont" select="'Courier, monospace'"/>
<!-- ========================= -->
<!-- root element: projectteam -->
<!-- ========================= -->
<xsl:template match="ROWSET">
<xsl:param name="totalno" select="''"/>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master
margin-right="1cm"
margin-left="1cm"
margin-bottom="1cm"
margin-top="1cm"
page-width="21cm"
page-height="29.7cm"
master-name="simpleA4">
<fo:region-body margin-bottom="1cm" margin-top="0.4cm">
</fo:region-body>
</fo:simple-page-master>
<fo:page-sequence-master master-name="reportpage">
<fo:repeatable-page-master-alternatives>
<fo:conditional-page-master-reference master-reference="simpleA4"/>
</fo:repeatable-page-master-alternatives>
</fo:page-sequence-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="reportpage">
<fo:flow flow-name="xsl-region-body">
<fo:block font-family="{$useFont}" text-align="center" font-weight="bold" font-size="12pt" space-after="5mm"> <xsl:value-of select="$auditTitle"/>
</fo:block>
<fo:block> </fo:block>
<fo:block font-family="{$useFont}" font-size="10pt"><xsl:value-of select="$transactionId"/></fo:block>
<fo:block font-family="{$useFont}" font-size="10pt"><xsl:value-of select="$modifiedBy"/></fo:block>
<fo:block font-family="{$useFont}" font-size="10pt"><xsl:value-of select="$modifiedDate"/></fo:block>
<fo:block> </fo:block>
<fo:block font-size="10pt">
<fo:table table-layout="fixed" width="100%" border-collapse="separate">
<fo:table-column column-width="3cm"/>
<fo:table-column column-width="2cm"/>
<fo:table-column column-width="4cm"/>
<fo:table-column column-width="4cm"/>
<fo:table-column column-width="4cm"/>
<fo:table-header>
<fo:table-row display-align="center">
<fo:table-cell number-columns-spanned="1" margin-right="1pt" border-width="0.500pt" border-style="solid" border-color="rgb(0,0,0)" margin-left="1pt" margin-bottom="1pt" margin-top="1pt" space-before.optimum="1.5pt" space-after.optimum="1.5pt" keep-together="always" height="15pt">
<fo:block font-family="{$useFont}" font-weight="bold" font-style="bold" text-align="center" font-size="10pt">
<xsl:value-of select="$fieldName"/>
</fo:block>
</fo:table-cell>
<fo:table-cell number-columns-spanned="1" margin-right="1pt" border-width="0.500pt" border-style="solid" border-color="rgb(0,0,0)" margin-left="1pt" margin-bottom="1pt" margin-top="1pt" space-before.optimum="1.5pt" space-after.optimum="1.5pt" keep-together="always" height="15pt">
<fo:block font-family="{$useFont}" font-weight="bold" text-align="center" font-size="10pt">
<xsl:value-of select="$operationType"/>
</fo:block>
</fo:table-cell>
<fo:table-cell number-columns-spanned="1" margin-right="1pt" border-width="0.500pt" border-style="solid" border-color="rgb(0,0,0)" margin-left="1pt" margin-bottom="1pt" margin-top="1pt" space-before.optimum="1.5pt" space-after.optimum="1.5pt" keep-together="always" height="15pt">
<fo:block font-family="{$useFont}" font-weight="bold" text-align="center" font-size="10pt">
<xsl:value-of select="$oldVal"/>
</fo:block>
</fo:table-cell>
<fo:table-cell number-columns-spanned="1" margin-right="1pt" border-width="0.500pt" border-style="solid" border-color="rgb(0,0,0)" margin-left="1pt" margin-bottom="1pt" margin-top="1pt" space-before.optimum="1.5pt" space-after.optimum="1.5pt" keep-together="always" height="15pt">
<fo:block font-family="{$useFont}" font-weight="bold" text-align="center" font-size="10pt">
<xsl:value-of select="$newVal"/>
</fo:block>
</fo:table-cell>
<fo:table-cell number-columns-spanned="1" margin-right="1pt" border-width="0.500pt" border-style="solid" border-color="rgb(0,0,0)" margin-left="1pt" margin-bottom="1pt" margin-top="1pt" space-before.optimum="1.5pt" space-after.optimum="1.5pt" keep-together="always" height="15pt">
<fo:block font-family="{$useFont}" font-weight="bold" text-align="center" font-size="10pt">
<xsl:value-of select="$entityName"/>
</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-header>
<fo:table-body>
<xsl:apply-templates select="ROW"/>
</fo:table-body>
</fo:table>
</fo:block>
<fo:block font-family="{$useFont}" font-size="10pt"><xsl:value-of select="$totalno"/></fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
<!-- ========================= -->
<!-- child element: member -->
<!-- ========================= -->
<xsl:template match="ROW">
<fo:table-row display-align="auto">
<fo:table-cell number-columns-spanned="1" margin-right="1pt" margin-left="1pt" border-width="0.500pt" border-style="solid" border-color="rgb(0,0,0)" margin-bottom="1pt" margin-top="1pt" space-before.optimum="1.5pt" space-after.optimum="1.5pt" keep-together="always" height="15pt">
<fo:block font-family="{$useFont}" font-weight="normal">
<xsl:value-of select="COL2" />
</fo:block>
</fo:table-cell>
<fo:table-cell number-columns-spanned="1" margin-right="1pt" margin-left="1pt" margin-bottom="1pt" border-width="0.500pt" border-style="solid" border-color="rgb(0,0,0)" margin-top="1pt" space-before.optimum="1.5pt" space-after.optimum="1.5pt" keep-together="always" height="15pt">
<fo:block font-family="{$useFont}" font-weight="normal">
<xsl:value-of select="COL1"/>
</fo:block>
</fo:table-cell>
<fo:table-cell number-columns-spanned="1" margin-right="1pt" margin-left="1pt" margin-bottom="1pt" border-width="0.500pt" border-style="solid" border-color="rgb(0,0,0)" margin-top="1pt" space-before.optimum="1.5pt" space-after.optimum="1.5pt" keep-together="always" height="15pt">
<fo:block font-family="{$useFont}" font-weight="normal">
<xsl:value-of select="COL4"/>
</fo:block>
</fo:table-cell>
<fo:table-cell number-columns-spanned="1" border-width="0.500pt" border-style="solid" border-color="rgb(0,0,0)" margin-right="1pt" margin-left="1pt" margin-bottom="1pt" margin-top="1pt" space-before.optimum="1.5pt" space-after.optimum="1.5pt" keep-together="always" height="15pt">
<fo:block font-family="{$useFont}" font-weight="normal">
<xsl:value-of select="COL5"/>
</fo:block>
</fo:table-cell>
<fo:table-cell number-columns-spanned="1" margin-right="1pt" margin-left="1pt" border-width="0.500pt" border-style="solid" border-color="rgb(0,0,0)" margin-bottom="1pt" margin-top="1pt" space-before.optimum="1.5pt" space-after.optimum="1.5pt" keep-together="always" height="15pt">
<fo:block font-family="{$useFont}" font-weight="normal">
<xsl:value-of select="COL10"/>
</fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:template>
</xsl:stylesheet>
I want to group on the COL12, and col8, col1
But I dont know how to grouping.
Please help me to get the grouping for the above xml.
I want result like this
Name: col12 value
Date: col8
User: col1 value
Field Name | Operation Type | Old Value | NewVal | Entity Name
passwordO.. I 1 CcsUserPassw...
seqUserPas.. I 1441 CcsUserPassw...
uuid I 6d7d... CcsUserPassw...
userId I SHREE CcsUserPassw...
and on page2
Name: col12 value
Date: col8
User: col1 value
Field Name | Operation Type | Old Value | NewVal | Entity Name
pwdChangeAtLogOn U 1 0 CcsUsersM
password U ***** ***** CcsUsersM
|
|

August 30th, 2010, 07:23 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
|
|
Your stylesheet has version="2.0" so assuming you use an XSLT 2.0 processor (like Saxon 9) you can use xsl:for-each-group to group data.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
|
|

August 30th, 2010, 07:43 AM
|
|
Registered User
|
|
Join Date: Aug 2010
Posts: 6
Thanks: 2
Thanked 0 Times in 0 Posts
|
|
Quote:
Originally Posted by Martin Honnen
Your stylesheet has version="2.0" so assuming you use an XSLT 2.0 processor (like Saxon 9) you can use xsl:for-each-group to group data.
|
Thanks for quick reply,
I've tried but I was getting exception that the lERROR: 'Unsupported XSL element 'http://www.w3.org/1999/XSL/Transform:for-each-group''java.lang.RuntimeException: Unsupported XSL element 'http://www.w3.org/1999/XSL/Transform:for-each-group'
I don't know the correct link for the above link.
and I am using apache FOP 0.95.
|
|

August 30th, 2010, 07:48 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
|
|
You will need to use Saxon 9 (from http://saxon.sourceforge.net/) if you want to use XSLT 2.0 with Java. How you plug Saxon 9 into your FOP processor Apache FOP I don't know, maybe someone else knows more, perhaps if Apache FOP has a user list ask there how to use a different XSLT processor.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
|
|

August 30th, 2010, 07:53 AM
|
|
Registered User
|
|
Join Date: Aug 2010
Posts: 6
Thanks: 2
Thanked 0 Times in 0 Posts
|
|
Quote:
Originally Posted by Martin Honnen
You will need to use Saxon 9 (from http://saxon.sourceforge.net/) if you want to use XSLT 2.0 with Java. How you plug Saxon 9 into your FOP processor Apache FOP I don't know, maybe someone else knows more, perhaps if Apache FOP has a user list ask there how to use a different XSLT processor.
|
Thanks for again quick reply.
I'll try it please let me know other way if there any.
|
|

August 30th, 2010, 01:48 PM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
There are several ways to use Saxon with FOP:
(a) from the command line (inefficient but easy) - first invoke Saxon to generate the XSL-FO output in a file, then invoke FOP to take the XSL-FO from a file
(b) from a Java application (efficient but needs a few lines of Java coding) - get a ContentHandler from FOP, wrap it is a SAXResult or SAXDestination and use this as the output of the Saxon transformation.
(c) using XProc to control the pipeline
(d) using xmlsh to control the pipeline
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
|
|
The Following User Says Thank You to mhkay For This Useful Post:
|
|
|

September 1st, 2010, 01:02 PM
|
|
Registered User
|
|
Join Date: Sep 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
xslt grouping and subgrouping method
My XML like this....
<dataroot>
<BU>
<Classification1>Air Cargo</Classification1>
<Customer>Freight International LLC</Customer>
<City>parco</City>
<Box>11745</Box>
<TelCode>04</TelCode>
<TelNo>3430060</TelNo>
<FaxNo>3430075</FaxNo>
<image>cargo.jpeg</image>
</BU>
<BU>
<Classification1>Air Cargo</Classification1>
<Customer>Freight International LLC</Customer>
<City>tazese</City>
<Box>11745</Box>
<TelCode>09</TelCode>
<TelNo>3431234</TelNo>
<FaxNo>3434321</FaxNo>
<image>cargo.jpeg</image>
</BU>
<BU>
<Classification1>Air Cargo</Classification1>
<Customer>Freight International LLC</Customer>
<City>raseus</City>
<Box>56899</Box>
<TelCode>08</TelCode>
<TelNo>347890</TelNo>
<FaxNo>345678</FaxNo>
<image>cargo.jpeg</image>
</BU>
</dataroot>
i would like result like this...
<?xml version="1.0" encoding="UTF-8"?>
<html>
<body>
<title>F</title>
<Image href="file:///D:/new%20dicrectory/Alpha%20New/images/cargo.jpeg"/>
<Customer>Freight International LLC</Customer>
<Address>Box 11745, parco, 04 3430060</Address>
<Address>Box 11745, tazese, 09 3431234</Address>
<Address>Box 56899, raseus, 08 347890</Address>
</body>
</html>
one customer having more branches so all branch list should come under one customer name for this case how to create xslt please give some idea.
advance thanks
|
|

September 1st, 2010, 02:10 PM
|
|
Registered User
|
|
Join Date: Sep 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
xslt grouping and subgrouping method
Hi Martin Honnen sir
how are you i am having some problem with xslt and xsl transformation
so how to contact you. already i try with your blog but message not post in your blog so please give your contact ID.
thanks
Last edited by akmeeran; September 1st, 2010 at 02:38 PM..
|
|

September 2nd, 2010, 03:30 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
Firstly, it is very bad to highjack another thread. If you are not the original poster and you have a different question with different XML and XSLT the start your own thread.
Secondly, you're not going to get a faster answer by spamming all the people who reply on this forum via their own email addresses. In fact your more likely to annoy them.
Thirdly - as previously stated - XSLT 2.0 and the <xsl:for-each-group> command are the way to go.
|
|

September 2nd, 2010, 05:22 AM
|
|
Registered User
|
|
Join Date: Sep 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi Samjudson
thanks for your reply,
I am not a programmer, now only i am learning, so can make modification my xslt as my required.
|
|
 |