Nested grouping using XSLT muenchian-grouping - xslt-1.0

I had to group a xml document in xslt 1.0 using Oracle Service Bus.
This is the sample input file(Simplified):
<?xml version="1.0" encoding="UTF-8"?>
<EMailData>
<property name="A">
<property name="B">
<property name="C">
<row>
<property name="C1">
<value>ValC1</value>
</property>
<property name="C2">
<value>ValC2</value>
</property>
<property name="C3">
<value>Valc3</value>
</property>
<property name="C4">
<value>Valc4</value>
</property>
</row>
</property>
<property name="C">
<row>
<property name="C1">
<value>ValC1</value>
</property>
<property name="C2">
<value>ValC2</value>
</property>
<property name="C3">
<value>Valc3</value>
</property>
<property name="C4">
<value>Valc4</value>
</property>
</row>
</property>
<property name="D">
<row>
<property name="D1">
<value>ValD1</value>
</property>
<property name="D2">
<value>VALd2</value>
</property>
<property name="D3-InnerElement"> //Need to Group this too
<row>
<property name="Status">
<value>Status122</value>
</property>
</row>
</property>
<property name="D3-InnerElement">
<row>
<property name="Status">
<value>Status123</value>
</property>
</row>
</property>
<property name="D3-InnerElement">
<row>
<property name="Status">
<value>Status124</value>
</property>
</row>
</property>
</row>
</property>
<property name="D">
<row>
<property name="D1">
<value>ValD1</value>
</property>
<property name="D2">
<value>VALd2</value>
</property>
<property name="D3-InnerElement">
<row>
<property name="Status">
<value>Status122</value>
</property>
</row>
</property>
<property name="D3-InnerElement">
<row>
<property name="Status">
<value>Status123</value>
</property>
</row>
</property>
<property name="D3-InnerElement">
<row>
<property name="Status">
<value>Status124</value>
</property>
</row>
</property>
</row>
</property>
</property>
</property>
</EMailData>
My XSLT Logic:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:strip-space elements="*"/>
<xsl:output indent="yes"/>
<xsl:key name="group" match="/*/*/*/property" use="#name"/>
<xsl:template match="#* | node()">
<xsl:copy>
<xsl:apply-templates select="#* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/*/*/*[property[#name]]">
<xsl:copy>
<xsl:copy-of select="#*"/>
<xsl:for-each select="*[generate-id() = generate-id(key('group', #name)[1])]">
<xsl:copy>
<xsl:copy-of select="#*"/>
<xsl:apply-templates select="key('group', #name)/*"/>
</xsl:copy>
</xsl:for-each>
</xsl:copy>
</xsl:template>
<!--Change for Inner Hierarchy-->
<xsl:key name="inner-group" match="/*/*/*/*/property" use="#name"/>
<xsl:template match="#* | node()">
<xsl:copy>
<xsl:apply-templates select="#* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/*/*/*/*[property[#name]]">
<xsl:copy>
<xsl:copy-of select="#*"/>
<xsl:for-each select="*[generate-id() = generate-id(key('inner-group', #name)[1])]">
<xsl:copy>
<xsl:copy-of select="#*"/>
<xsl:apply-templates select="key('inner-group', #name)/*"/>
</xsl:copy>
</xsl:for-each>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Anticipated o/p
<?xml version="1.0" encoding="UTF-8"?>
<EMailData>
<property name="A">
<property name="B">
<property name="C">
<row>
<property name="C1">
<value>ValC1</value>
</property>
<property name="C2">
<value>ValC2</value>
</property>
<property name="C3">
<value>Valc3</value>
</property>
<property name="C4">
<value>Valc4</value>
</property>
</row>
<row>
<property name="C1">
<value>ValC1</value>
</property>
<property name="C2">
<value>ValC2</value>
</property>
<property name="C3">
<value>Valc3</value>
</property>
<property name="C4">
<value>Valc4</value>
</property>
</row>
</property>
<property name="D">
<row>
<property name="D1">
<value>ValD1</value>
</property>
<property name="D2">
<value>VALd2</value>
</property>
<property name="D3-InnerElement"> //Need to Group this too
<row>
<property name="Status">
<value>Status122</value>
</property>
</row>
</property>
<property name="D3-InnerElement">
<row>
<property name="Status">
<value>Status123</value>
</property>
</row>
<row>
<property name="Status">
<value>Status124</value>
</property>
</row>
</property>
</row>
<row>
<property name="D1">
<value>ValD1</value>
</property>
<property name="D2">
<value>VALd2</value>
</property>
<property name="D3-InnerElement">
<row>
<property name="Status">
<value>Status122</value>
</property>
</row>
<row>
<property name="Status">
<value>Status123</value>
</property>
</row>
<row>
<property name="Status">
<value>Status124</value>
</property>
</row>
</property>
</row>
</property>
</property>
</property>
</EMailData>
But The D3-innerelement is not grouped. Tell me Where I went wrong!!
o/p For my XSLT
<?xml version="1.0" encoding="UTF-8"?>
<EMailData>
<property name="A">
<property name="B">
<property name="C">
<row>
<property name="C1">
<value>ValC1</value>
</property>
<property name="C2">
<value>ValC2</value>
</property>
<property name="C3">
<value>Valc3</value>
</property>
<property name="C4">
<value>Valc4</value>
</property>
</row>
<row>
<property name="C1">
<value>ValC1</value>
</property>
<property name="C2">
<value>ValC2</value>
</property>
<property name="C3">
<value>Valc3</value>
</property>
<property name="C4">
<value>Valc4</value>
</property>
</row>
</property>
<property name="D">
<row>
<property name="D1">
<value>ValD1</value>
</property>
<property name="D2">
<value>VALd2</value>
</property>
<property name="D3-InnerElement"> //Need to Group this too
<row>
<property name="Status">
<value>Status122</value>
</property>
</row>
</property>
<property name="D3-InnerElement">
<row>
<property name="Status">
<value>Status123</value>
</property>
</row>
</property>
<property name="D3-InnerElement">
<row>
<property name="Status">
<value>Status124</value>
</property>
</row>
</property>
</row>
<row>
<property name="D1">
<value>ValD1</value>
</property>
<property name="D2">
<value>VALd2</value>
</property>
<property name="D3-InnerElement">
<row>
<property name="Status">
<value>Status122</value>
</property>
</row>
</property>
<property name="D3-InnerElement">
<row>
<property name="Status">
<value>Status123</value>
</property>
</row>
</property>
<property name="D3-InnerElement">
<row>
<property name="Status">
<value>Status124</value>
</property>
</row>
</property>
</row>
</property>
</property>
</property>
</EMailData>
Thanks in Advance!

And here goes the solution using Muenchian's grouping:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:strip-space elements="*"/>
<xsl:output method="xml" indent="yes"/>
<xsl:key name="group" match="property" use="#name"/>
<xsl:template match="/EMailData/property/property | /EMailData/property/property/property/row">
<xsl:variable name="id" select="generate-id()"/>
<xsl:copy>
<xsl:copy-of select="#*"/>
<xsl:for-each select="property[count(. | key('group', #name)[$id = generate-id(parent::*)][1]) = 1]">
<xsl:copy>
<xsl:copy-of select="#*"/>
<xsl:apply-templates select="key('group', #name)[$id = generate-id(parent::*)]/*"/>
</xsl:copy>
</xsl:for-each>
</xsl:copy>
</xsl:template>
<xsl:template match="#* | node()">
<xsl:copy>
<xsl:apply-templates select="#* | node()" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>

This solution isn't based on Muenchian's grouping, but thought it would be helpful:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:strip-space elements="*"/>
<xsl:output method="xml" indent="yes"/>
<xsl:template match="*[property]">
<xsl:copy>
<xsl:copy-of select="#*"/>
<xsl:for-each select="property[not(#name = preceding-sibling::property/#name)]">
<xsl:copy>
<xsl:copy-of select="#*"/>
<xsl:apply-templates select="../property[#name = current()/#name]/*"/>
</xsl:copy>
</xsl:for-each>
</xsl:copy>
</xsl:template>
<xsl:template match="#* | node()">
<xsl:copy>
<xsl:apply-templates select="#* | node()" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Here, the second template is the identity transform template, used to copy all attributes and nodes.
The first template matches elements with at least one property child, or in simple words, "parents of the property elements to be grouped by #name".
You may, as well, change the template match to:
<xsl:template match="/EMailData/property/property | /EMailData/property/property/property/row">
The for-each is on the first property with a specific #name value in the current parent(see the condition using preceding-sibling).
And for every iteration, templates are applied for all the child elements of property elements with the current(for-each element's) #name, i.e., grouping property elements of a single parent by their #name's value.
The same template is called for the inner property elements, grouping even those by #name.

Related

Multiple groupings of XML nodes

I'm trying to group the input below by the destination and assortment values using muenchian-grouping which is new for me so I'm not sure how to do it properly. The input files will be much larger than this so performance is important.
<?xml version="1.0"?>
<ns0:Data xmlns:ns0="http://BizTalk_Projects.input">
<transports>
<destination>destination 1</destination>
<assortment>Volvo_GA961</assortment>
<quantity>10</quantity>
</transports>
<transports>
<destination>destination 1</destination>
<assortment>Volvo_GA961</assortment>
<quantity>15</quantity>
</transports>
<transports>
<destination>destination 1</destination>
<assortment>Volvo_GA969</assortment>
<quantity>15</quantity>
</transports>
<transports>
<destination>destination 1</destination>
<assortment>Volvo_GA972</assortment>
<quantity>5</quantity>
</transports>
<transports>
<destination>destination 1</destination>
<assortment>Volvo_SA980</assortment>
<quantity>20</quantity>
</transports>
<transports>
<destination>destination 2</destination>
<assortment>Volvo_GA960</assortment>
<quantity>10</quantity>
</transports>
<transports>
<destination>destination 1</destination>
<assortment>Nissan_GA963</assortment>
<quantity>5</quantity>
</transports>
<transports>
<destination>destination 1</destination>
<assortment>Nissan_GA963</assortment>
<quantity>5</quantity>
</transports>
</ns0:Data>
Expected output:
<?xml version="1.0" encoding="UTF-8"?>
<ns0:Destinations xmlns:ns0="http://BizTalk_Projects.output">
<Destination>
<name>destination 1</name>
<assortment>
<name>Volvo_GA</name>
<row>
<type>sumPerAssortment</type>
<id>961</id>
<totalQuantity>25</totalQuantity>
<region>1</region>
</row>
<row>
<type>sumPerAssortment</type>
<id>969</id>
<totalQuantity>15</totalQuantity>
<region>1</region>
</row>
<row>
<type>sumPerAssortment</type>
<id>972</id>
<totalQuantity>5</totalQuantity>
<region>2</region>
</row>
<row>
<type>sumPerRegion</type>
<id />
<totalQuantity>40</totalQuantity>
<region>1</region>
</row>
<row>
<type>sumPerRegion</type>
<id />
<totalQuantity>5</totalQuantity>
<region>2</region>
</row>
<row>
<type>totalSum</type>
<id />
<totalQuantity>45</totalQuantity>
<region />
</row>
</assortment>
<assortment>
<name>Volvo_SA</name>
<row>
<type>sumPerAssortment</type>
<id>980</id>
<totalQuantity>20</totalQuantity>
<region>3</region>
</row>
<row>
<type>sumPerRegion</type>
<id />
<totalQuantity>20</totalQuantity>
<region>3</region>
</row>
<row>
<type>totalSum</type>
<id />
<totalQuantity>20</totalQuantity>
<region />
</row>
</assortment>
<assortment>
<name>Nissan_GA</name>
<row>
<type>sumPerAssortment</type>
<id>963</id>
<totalQuantity>10</totalQuantity>
<region>1</region>
</row>
<row>
<type>sumPerRegion</type>
<id />
<totalQuantity>10</totalQuantity>
<region>1</region>
</row>
<row>
<type>totalSum</type>
<id />
<totalQuantity>10</totalQuantity>
<region />
</row>
</assortment>
</Destination>
<Destination>
<name>destination 2</name>
<assortment>
<name>Volvo_GA</name>
<row>
<type>sumPerAssortment</type>
<id>960</id>
<totalQuantity>10</totalQuantity>
<region>1</region>
</row>
<row>
<type>sumPerRegion</type>
<id />
<totalQuantity>10</totalQuantity>
<region>1</region>
</row>
<row>
<type>totalSum</type>
<id />
<totalQuantity>10</totalQuantity>
<region />
</row>
</assortment>
</Destination>
</ns0:Destinations>
Note:
assortment number starting with 96 = region 1
assortment number starting with 97 = region 2
assortment number starting with 98 = region 3
Start of my XSLT:
<?xml version="1.0" encoding="UTF-16"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:var="http://schemas.microsoft.com/BizTalk/2003/var"
exclude-result-prefixes="msxsl var s0"
version="1.0"
xmlns:s0="http://BizTalk_Projects.input"
xmlns:ns0="http://BizTalk_Projects.output">
<xsl:output omit-xml-declaration="yes" method="xml" version="1.0" />
<xsl:key name="destinationKey" match="transports" use="destination"/>
<xsl:template match="/">
<xsl:apply-templates select="/s0:Data" />
</xsl:template>
<xsl:template match="/s0:Data">
<ns0:Destinations>
<xsl:for-each select="transports[count(. | key('destinationKey',destination)[1]) = 1]">
<Destination>
<name>
<xsl:value-of select="destination/text()" />
</name>
<xsl:for-each select="key('destinationKey',destination)">
<assortment>
<name>
<xsl:value-of select="substring(assortment/text(),1,string-length(assortment)-3)" />
</name>
</assortment>
</xsl:for-each>
</Destination>
</xsl:for-each>
</ns0:Destinations>
</xsl:template>
</xsl:stylesheet>
With this code, I'm getting this output (duplicate rows, but correct assortments for each destination);
<ns0:Destinations xmlns:ns0="http://BizTalk_Projects.output">
<Destination>
<name>destination 1</name>
<assortment>
<name>Volvo_GA</name>
</assortment>
<assortment>
<name>Volvo_GA</name>
</assortment>
<assortment>
<name>Volvo_GA</name>
</assortment>
<assortment>
<name>Volvo_GA</name>
</assortment>
<assortment>
<name>Volvo_SA</name>
</assortment>
<assortment>
<name>Nissan_GA</name>
</assortment>
<assortment>
<name>Nissan_GA</name>
</assortment>
</Destination>
<Destination>
<name>destination 2</name>
<assortment>
<name>Volvo_GA</name>
</assortment>
</Destination>
</ns0:Destinations>
Any suggestions on how I can solve this? Help is very appreciated!
It's difficult to see how exactly the output relates to the input. Try this as your starting point:
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:key name="transports-by-destination" match="transports" use="destination" />
<xsl:key name="transports-by-assortment" match="transports" use="concat(destination, '|', assortment)" />
<xsl:template match="/*">
<xsl:copy>
<!-- for each unique destination -->
<xsl:for-each select="transports[count(. | key('transports-by-destination', destination)[1]) = 1]">
<Destination>
<name>
<xsl:value-of select="destination"/>
</name>
<xsl:variable name="group" select="key('transports-by-destination', destination)" />
<!-- for each unique assortment in this destination -->
<xsl:for-each select="$group[count(. | key('transports-by-assortment', concat(destination, '|', assortment))[1]) = 1]">
<assortment>
<name>
<xsl:value-of select="assortment"/>
</name>
<!-- process this subgroup -->
<xsl:for-each select="key('transports-by-assortment', concat(destination, '|', assortment))" >
<row>
<!-- not sure what goes in here -->
<totalQuantity>
<xsl:value-of select="quantity"/>
</totalQuantity>
</row>
</xsl:for-each>
</assortment>
</xsl:for-each>
</Destination>
</xsl:for-each>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>

XSLT transformation converting elements to attributes

I am trying to transform this XML file :
<database name="sql_sales">
<!-- Table Customer -->
<table name="Customer">
<column name="CustomerID">1</column>
<column name="Name">Roth Farrell</column>
<column name="Age">50</column>
<column name="Country">Canada</column>
<column name="City">Fermont</column>
<column name="Signup_date">2013-03-09 16:34:13</column>
<column name="Channel">Coupon</column>
</table>
<table name="Customer">
<column name="CustomerID">3</column>
<column name="Name">Randall Mosley</column>
<column name="Age">20</column>
<column name="Country">Belgium</column>
<column name="City">Leuze</column>
<column name="Signup_date">2012-03-26 04:02:37</column>
<column name="Channel">SEO</column>
</table>
</database>
to this format:
<dataset>
<Cust CustomerID="1" Name="Roth Farrell" Age="50" Country="Canada" City="Fermont" Signup_date="2012-04-26 17:34:13.0" Channel="Coupon"/>
<Cust CustomerID="3" Name="Randall Mosley" Age="20" Country="Belgium" City="Leuze" Signup_date="2011-05-14 05:02:37.0" Channel="SEO"/>
</dataset>
I am new to XSLT, How can I do this with XSLT?
thanks
Use
<xsl:template match="database">
<dataset>
<xsl:apply-templates/>
</dataset>
</xsl:template>
<xsl:template match="table[#name = 'Customer']">
<Cust>
<xsl:apply-templates select="column"/>
</Cust>
</xsl:template>
<xsl:template match="column">
<xsl:attribute name="{#name}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:template>

I need to iterate through the xml values and produce a xls file with the values in it

I have a requirement to generate the xls file with the values from the xml.Below is the sequence I am trying to do but it only takes the first result.
<sequence xmlns="http://ws.apache.org/ns/synapse" name="ConcurTransformReconcilationExtractFlow">
<property xmlns:ns="http://org.apache.synapse/xsd" xmlns:ns3="http://org.apache.synapse/xsd" name="current-context-details" expression="concat(get-property('current-context-details'), ', ConcurTransformReconcilationExtractFlow')" />
<property name="scenario" value="ConcurTransformReconcilationExtractFlow" />
<log level="custom">
<property name="DEBUGGING" value="ConcurTransformReconcilationExtractFlow" />
</log>
<log>
<property xmlns:ns="http://org.apache.synapse/xsd" xmlns:ns3="http://org.apache.synapse/xsd" name="datetime" expression="substring(get-property('current-date'),1,10)" />
<property xmlns:ns="http://org.apache.synapse/xsd" xmlns:ns3="http://org.apache.synapse/xsd" name="date" expression="substring-after(get-property('current-date'), 'T')" />
<property xmlns:ns="http://org.apache.synapse/xsd" xmlns:ns3="http://org.apache.synapse/xsd" name="time" expression="substring(substring-after(get-property('current-date'), 'T'), 1,8)" />
<property xmlns:ns="http://org.apache.synapse/xsd" xmlns:ns3="http://org.apache.synapse/xsd" name="current-datetime" expression="concat(substring(get-property('current-date'),1,10),substring(substring-after(get-property('current-date'), 'T'), 1,8))" />
</log>
<filter xmlns:dat="http://ws.wso2.org/dataservice" xmlns:ns="http://org.apache.synapse/xsd" xmlns:ns3="http://org.apache.synapse/xsd" xpath="//dat:rows">
<then>
<xslt key="Concur_Group_Reconcilation_Extract_Transformation" />
<log level="full" />
<iterate expression="//sae" sequential="true">
<target>
<sequence>
<property name="company_code_sae_id" expression="concat('_',string(//#filename))" />
<log level="custom">
<property name="company_code_sae_id" expression="get-property('company_code_sae_id')" />
</log>
<property name="filename" expression="concat('Reconcilation_Extract_',substring(get-property('current-date'),1,10),'.xls')" />
<class name="com.semtech.integration.mediator.XMLToExcelMediator.XMLToExcelMediator" />
<property name="transport.vfs.ReplyFileName" expression="get-property('filename')" scope="transport" />
<property name="OUT_ONLY" value="true" />
<filter source="starts-with(get-property('company_code_sae_id'),'_')" regex="true">
<then>
<send>
<endpoint name="FileEpr">
<address uri="vfs:file:///exports/mounts/Concur/PaymentExtract" />
</endpoint>
</send>
</then>
</filter>
</sequence>
</target>
</iterate>
</then>
<else>
<enrich>
<source clone="true" type="body" xpath="" property="" />
<target action="replace" type="property" xpath="" property="body-message" />
</enrich>
<property name="error_message" expression="get-property('body-message')" />
<property name="error_message" expression="concat('Invalid response received from data service: ', get-property('error_message'))" />
<log level="custom" category="ERROR">
<property name="ConcurTransformReconcilationExtractFlow" expression="get-property('error_message')" />
</log>
<sequence key="GeneralErrorHandler" />
<drop />
</else>
</filter>
<description>Transforms the XML extract data service response to a xml file.</description>
</sequence>
Input after the xslt transformation is as below
<?xml version="1.0"?>
<rows>
<sae filename="30">
<row>
<sae_id>6</sae_id>
<sae_date>2012-08-13-07:00</sae_date>
<Co30>314.42</Co30>
<payment_type>CASH</payment_type>
<concur_pay>N</concur_pay>
</row>
<row>
<sae_id>7</sae_id>
<sae_date>2012-08-20-07:00</sae_date>
<Co30>1456.62</Co30>
<payment_type>CASH</payment_type>
<concur_pay>N</concur_pay>
</row>
<row>
<sae_id>10</sae_id>
<sae_date>2012-09-08-07:00</sae_date>
<Co30>1359.88</Co30>
<payment_type>CASH</payment_type>
<concur_pay>N</concur_pay>
</row>
<row>
<sae_id>12</sae_id>
<sae_date>2012-09-18-07:00</sae_date>
<Co30>44.4</Co30>
<payment_type>CASH</payment_type>
<concur_pay>N</concur_pay>
</row>
<row>
<sae_id>15</sae_id>
<sae_date>2012-09-24-07:00</sae_date>
<Co30>2142.47</Co30>
<payment_type>CASH</payment_type>
<concur_pay>N</concur_pay>
</row>
<row>
<sae_id>19</sae_id>
<sae_date>2012-09-28-07:00</sae_date>
<Co30>3400.9</Co30>
<payment_type>CASH</payment_type>
<concur_pay>Y</concur_pay>
</row>
<row>
<sae_id>28</sae_id>
<sae_date>2012-10-03-07:00</sae_date>
<Co30>1243.89</Co30>
<payment_type>CASH</payment_type>
<concur_pay>Y</concur_pay>
</row>
<row>
<sae_id>33</sae_id>
<sae_date>2012-10-10-07:00</sae_date>
<Co30>101.88</Co30>
<payment_type>CASH</payment_type>
<concur_pay>Y</concur_pay>
</row>
<row>
<sae_id>36</sae_id>
<sae_date>2012-10-15-07:00</sae_date>
<Co30>2418.88</Co30>
<payment_type>CASH</payment_type>
<concur_pay>N</concur_pay>
</row>
<row>
<sae_id>40</sae_id>
<sae_date>2012-10-22-07:00</sae_date>
<Co30>1499.57</Co30>
<payment_type>CASH</payment_type>
<concur_pay>Y</concur_pay>
</row>
<row>
<sae_id>41</sae_id>
<sae_date>2012-10-23-07:00</sae_date>
<Co30>925.88</Co30>
<payment_type>CASH</payment_type>
<concur_pay>Y</concur_pay>
</row>
<row>
<sae_id>43</sae_id>
<sae_date>2012-10-25-07:00</sae_date>
<Co30>37.0</Co30>
<payment_type>CASH</payment_type>
<concur_pay>N</concur_pay>
</row>
<row>
<sae_id>44</sae_id>
<sae_date>2012-10-26-07:00</sae_date>
<Co30>1046.34</Co30>
<payment_type>CASH</payment_type>
<concur_pay>N</concur_pay>
</row>
<row>
<sae_id>46</sae_id>
<sae_date>2012-10-30-07:00</sae_date>
<Co30>3760.52</Co30>
<payment_type>CASH</payment_type>
<concur_pay>N</concur_pay>
</row>
<row>
<sae_id>51</sae_id>
<sae_date>2012-11-06-08:00</sae_date>
<Co30>1610.96</Co30>
<payment_type>CASH</payment_type>
<concur_pay>Y</concur_pay>
</row>
<row>
<sae_id>53</sae_id>
<sae_date>2012-11-08-08:00</sae_date>
<Co30>1962.57</Co30>
<payment_type>CASH</payment_type>
<concur_pay>N</concur_pay>
</row>
<row>
<sae_id>53</sae_id>
<sae_date>2012-11-08-08:00</sae_date>
<Co30>868.0</Co30>
<payment_type>COPD</payment_type>
<concur_pay>N</concur_pay>
</row>
<row>
<sae_id>56</sae_id>
<sae_date>2012-11-13-08:00</sae_date>
<Co30>11384.52</Co30>
<payment_type>CASH</payment_type>
<concur_pay>N</concur_pay>
</row>
<row>
<sae_id>56</sae_id>
<sae_date>2012-11-13-08:00</sae_date>
<Co30>2268.4</Co30>
<payment_type>COPD</payment_type>
<concur_pay>N</concur_pay>
</row>
<row>
<sae_id>59</sae_id>
<sae_date>2012-11-16-08:00</sae_date>
<Co30>750.15</Co30>
<payment_type>CASH</payment_type>
<concur_pay>Y</concur_pay>
</row>
<row>
<sae_id>61</sae_id>
<sae_date>2012-11-20-08:00</sae_date>
<Co30>1083.08</Co30>
<payment_type>CASH</payment_type>
<concur_pay>Y</concur_pay>
</row>
<row>
<sae_id>66</sae_id>
<sae_date>2012-11-27-08:00</sae_date>
<Co30>14624.52</Co30>
<payment_type>CASH</payment_type>
<concur_pay>N</concur_pay>
</row>
<row>
<sae_id>66</sae_id>
<sae_date>2012-11-27-08:00</sae_date>
<Co30>5874.2</Co30>
<payment_type>COPD</payment_type>
<concur_pay>N</concur_pay>
</row>
<row>
<sae_id>69</sae_id>
<sae_date>2012-11-30-08:00</sae_date>
<Co30>19.96</Co30>
<payment_type>CASH</payment_type>
<concur_pay>Y</concur_pay>
</row>
<row>
<sae_id>71</sae_id>
<sae_date>2012-12-04-08:00</sae_date>
<Co30>595.13</Co30>
<payment_type>CASH</payment_type>
<concur_pay>N</concur_pay>
</row>
<row>
<sae_id>75</sae_id>
<sae_date>2012-12-06-08:00</sae_date>
<Co30>685.47</Co30>
<payment_type>CASH</payment_type>
<concur_pay>N</concur_pay>
</row>
<row>
<sae_id>76</sae_id>
<sae_date>2012-12-07-08:00</sae_date>
<Co30>1286.91</Co30>
<payment_type>CASH</payment_type>
<concur_pay>N</concur_pay></row>
</sae>
</row>
</sae>
<sae filename="36">
<row>
<sae_id>53</sae_id>
<sae_date>2012-11-08-08:00</sae_date>
<Co36>631.8</Co36>
<payment_type>CASH</payment_type>
<concur_pay>Y</concur_pay>
</row>
<row>
<sae_id>56</sae_id>
<sae_date>2012-11-13-08:00</sae_date>
<Co36>1041.87</Co36>
<payment_type>CASH</payment_type>
<concur_pay>N</concur_pay>
</row>
<row>
<sae_id>58</sae_id>
<sae_date>2012-11-15-08:00</sae_date>
<Co36>3197.3</Co36>
<payment_type>CASH</payment_type>
<concur_pay>Y</concur_pay>
</row>
<row>
<sae_id>66</sae_id>
<sae_date>2012-11-27-08:00</sae_date>
<Co36>4912.54</Co36>
<payment_type>CASH</payment_type>
<concur_pay>N</concur_pay>
</row>
<row>
<sae_id>71</sae_id>
<sae_date>2012-12-04-08:00</sae_date>
<Co36>1008.42</Co36>
<payment_type>CASH</payment_type>
<concur_pay>Y</concur_pay>
</row>
<row>
<sae_id>76</sae_id>
<sae_date>2012-12-07-08:00</sae_date>
<Co36>46.62</Co36>
<payment_type>CASH</payment_type>
<concur_pay>N</concur_pay>
</row>
</sae>
<sae filename="33">
<row>
<sae_id>56</sae_id>
<sae_date>2012-11-13-08:00</sae_date>
<Co33>200.43</Co33>
<payment_type>CASH</payment_type>
<concur_pay>N</concur_pay>
</row>
<row>
<sae_id>56</sae_id>
<sae_date>2012-11-13-08:00</sae_date>
<Co33>950.2</Co33>
<payment_type>COPD</payment_type>
<concur_pay>N</concur_pay>
</row>
<row>
<sae_id>58</sae_id>
<sae_date>2012-11-15-08:00</sae_date>
<Co33>3231.53</Co33>
<payment_type>CASH</payment_type>
<concur_pay>Y</concur_pay>
</row>
<row>
<sae_id>62</sae_id>
<sae_date>2012-11-21-08:00</sae_date>
<Co33>156.66</Co33>
<payment_type>CASH</payment_type>
<concur_pay>N</concur_pay>
</row>
<row>
<sae_id>62</sae_id>
<sae_date>2012-11-21-08:00</sae_date>
<Co33>2806.92</Co33>
<payment_type>COPD</payment_type>
<concur_pay>N</concur_pay>
</row>
<row>
<sae_id>66</sae_id>
<sae_date>2012-11-27-08:00</sae_date>
<Co33>291.48</Co33>
<payment_type>CASH</payment_type>
<concur_pay>N</concur_pay>
</row>
<row>
<sae_id>69</sae_id>
<sae_date>2012-11-30-08:00</sae_date>
<Co33>47.78</Co33>
<payment_type>CASH</payment_type>
<concur_pay>Y</concur_pay>
</row>
</sae>
</rows>
And the output needs to be a xls file with columns as below
sae_id sae_date Co30 Co33 Co36 Payment_type concur_pay
Under this all the values should be properly alloted.The sequence above does it but only either for the first value if sequential="true" or only for the last value if sequential="false".Please guide me to get all the values in single xls file
Just tried out your sequence with a proxy (see below code) taking your input XML (which contained errors!). Well It does work nicely. The problem is here:
While you are looping with the iterate over the <sae> elements (which does work) you are always writing into the same filename! The property transport.vfs.ReplyFileName is always the same. So when you use sequential="true" you will have the content of the last <sae> in the output file. But when you use sequential="false" the sequence is not really defined and you will get any of the elements.
Here I changed the output filename with the company_cod_sae_id and then you will have one output file per sae.
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse" name="stackoverflow_xls" transports="vfs" startOnLoad="true" trace="disable">
<parameter name="transport.PollInterval">5</parameter>
<parameter name="transport.vfs.FileURI">C:/WSO2/StackOverflow/XLS</parameter>
<parameter name="transport.vfs.FileNamePattern">.*.(XML|xml)$</parameter>
<parameter name="transport.vfs.ContentType">application/xml</parameter>
<parameter name="transport.vfs.ActionAfterProcess">MOVE</parameter>
<parameter name="transport.vfs.MoveAfterProcess">C:/WSO2/StackOverflow/XLS/saved</parameter>
<target faultSequence="errorSequence">
<inSequence>
<log level="full"/>
<iterate expression="//sae" sequential="true">
<target>
<sequence>
<property name="company_code_sae_id" expression="concat('_',string(//#filename))"/>
<log level="custom">
<property name="company_code_sae_id" expression="get-property('company_code_sae_id')"/>
</log>
<!--<property name="filename" expression="concat('Reconcilation_Extract_',substring(get-property('current-date'),1,10),'.xls')"/>-->
<property name="filename" expression="concat('Reconcilation_Extract_',get-property('company_code_sae_id'),'.xls')"/>
<!--<class name="com.semtech.integration.mediator.XMLToExcelMediator.XMLToExcelMediator"/>-->
<property name="transport.vfs.ReplyFileName" expression="get-property('filename')" scope="transport"/>
<property name="OUT_ONLY" value="true"/>
<filter source="starts-with(get-property('company_code_sae_id'),'_')" regex="true">
<then>
<send>
<endpoint name="FileEpr">
<address uri="vfs:file://C:/WSO2/StackOverflow/XLS"/>
</endpoint>
</send>
</then>
</filter>
</sequence>
</target>
</iterate>
</inSequence>
</target>

How to call stored proc using nhibernate?

I have research about it and all solution are pointing out to one solution, to use the libe of codes below and put it int .hbm.xml file. but I do not have one. What I have is hibernate.cfg.xml and nhvalidator.cfg.xml.
I have read from here : http://forums.asp.net/t/1407518.aspx/1
but where can I type the query tags? I typed it in the hibernate.cfg.xml (see below) but it is not working.
<?xml version="1.0" encoding="utf-16"?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<property name="connection.connection_string">Server=localhost\MSSQLSERVERR2;Database=SupplierSearch;Trusted_Connection=True</property>
<property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
<property name="cache.use_minimal_puts">false</property>
<property name="use_outer_join">false</property>
</session-factory>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="Quarry.SupplierSearch"
assembly="SupplierSearch">
<class name="SupplierSearch" table="Client" lazy="true">
<id name="ClientId" column="ClientId">
<generator class="native" />
</id>
<property name="FirstName" column="FirstName" />
<property name="ClientId" column="ClientId" />
<loader query-ref="GetAllClient"/>
</class>
<sql-query name="GetAllClient" >
<return alias="GetAllClient" class="SupplierSearch">
<return-property name="ClientId" column="ClientId"/>
<return-property name="FirstName" column="FirstName"/>
</return>
exec GetAllClient
</sql-query>
</hibernate-mapping>
</hibernate-configuration>
since it is not working, I tried typing it in my Client.nhv.xml (see below) where client is mapped)
<?xml version="1.0" encoding="utf-8"?>
<nhv-mapping assembly="Quarry.SupplierSearch" namespace="Quarry.SupplierSearch.Model" xmlns="urn:nhibernate-validator-1.0">
<class name="Client">
<property name="Address1">
<not-null />
</property>
<property name="Address2">
<not-null />
</property>
<property name="BusinessName">
<not-null />
</property>
<property name="ClientId">
<not-null />
<digits integerDigits="10" />
</property>
<property name="Country">
<not-null />
</property>
<property name="FirstName">
<not-null />
</property>
<property name="LastName">
<not-null />
</property>
<property name="ListingType">
<not-null />
<digits integerDigits="10" />
</property>
<property name="PhoneNumber">
<not-null />
</property>
<property name="PostCode">
<not-null />
</property>
<property name="State">
<not-null />
</property>
</class>
<loader query-ref="GetAllClient"/>
<sql-query name="GetAllClient">
<load-collection alias="Clients" role ="Client"/>
exec [GetAllClient]
</sql-query>
</nhv-mapping>
any suggestion to get this working? thanks
It needs to be called Client.hbm.xml not Client.hbv.xmland an embedded resource.
edit I not familiar with any tools that generate hbv nor have I ever seen a mapping that begins with <nhv-mapping .. >. There must be a custom plugin/dll that you must use to get this working. What tool are you using?
However have you seen this blog post to get SP's to work without any custom tools.
using stored procedures is not supported with load-collection (scalar only).
use the format:
<sql-query name="GetAllClient">
<load-collection alias="Clients" role ="Client"/>
SELECT {c.*}
FROM client c
</sql-query>
(with the stuff in your stored proc innards in place of the "SELECT...FROM..." part of course.)

Can I load an image file into "GTk-glad" Tool as a GUI frame to work on it?

I know that "GtK-glade" got many convinent sample GUI frame like Management UI, there are many samples using the template of Glade's inside tool, like buttons, menus, label.
But I had like to use my own frame of GUI to be costumerized for users.And I just can't find a way to load my own "image" of frame from the "Glade" tool.
By What method can I let my one "image" of frame to replace the sample frame of "Glade" tool?
Or by what kind of "GtK" glade-like tooling can do this job?
I use c souce code of Ubuntu linux. And I can't find an toolkit to update my original souce code of GUI. I only find that GTK-glade can open it .
int
main (int argc, char *argv[])
..........
GtkImage *image = NULL;
image = glade_xml_get_widget (gxml, "image1");
gtk_image_set_from_file(image,"tux.png");
my glade xml file is:
<?xml version="1.0"?>
<glade-interface>
<!-- interface-requires gtk+ 2.6 -->
<!-- interface-naming-policy toplevel-contextual -->
<widget class="GtkWindow" id="window1">
<property name="visible">True</property>
<property name="border_width">10</property>
<property name="title" translatable="yes">window1</property>
<property name="default_width">800</property>
<property name="default_height">480</property>
<signal name="destroy" handler="on_window1_destroy"/>
<child>
<widget class="GtkVBox" id="vbox2">
<property name="visible">True</property>
<property name="spacing">2</property>
<child>
<widget class="GtkEntry" id="entry1">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">รข</property>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<widget class="GtkButton" id="button1">
<property name="label" translatable="yes">Hello</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="use_underline">True</property>
<signal name="clicked" handler="on_button1_clicked"/>
</widget>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="label" translatable="yes">label</property>
</widget>
<packing>
<property name="position">2</property>
</packing>
</child>
<child>
<widget class="GtkImage" id="image1">
<property name="visible">True</property>
<property name="stock">gtk-missing-image</property>
</widget>
<packing>
<property name="position">3</property>
</packing>
</child>
</widget>
</child>
</widget>
</glade-interface>