XSL looping is not occurring properly at each level - loops

I need to loop though this SAP IDOC to report shipment data. I need to break at each change of E2EDT37_KDMAT (part number), E2EDT37_VHILM_KU (package type) and E2EDT37_QUANTITY in the G07 node (PACKAGE). The current code seemed to work until there was more than one G16 (DELIVERY) node within a G01 (SHIPMENT) node.
This snippet of code doesn't produce XML output and the issue is seen in the message output.
I believe the method I am trying is just not valid and I will find another way. But I don't understand why exactly. I've tried preceding-sibling instead of preceding and just got different wrong output.
Each loop uses the same predicate as the last with one more criterion added to identify all matching the E2EDT37 records and perform the next statement once for each unique value of E2EDT37_KDMAT, E2EDT37_VHILM_KU and lastly E2EDT37_QUANTITY. It seems to come so close but never gets it right. What is my misunderstanding of the way E2EDT37_KDMAT[not(.=preceding::E2EDT37_KDMAT)] works here?
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.1" xmlns:exsl="http://exslt.org/common"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:XmlTransform="java:de.axway.converter.xml.xsltextensions.XsltExtensions" exclude-result-prefixes="XmlTransform xsl exsl">
<xsl:output method="xml" indent="yes" encoding="UTF-8"/>
<xsl:template match="/ACTIS">
<xsl:message></xsl:message>
<xsl:call-template name="DESADV_D96A"/>
</xsl:template>
<xsl:template name="DESADV_D96A">
<xsl:for-each select="//G16">
<xsl:variable name="current-delivery" select="E2EDL20/E2EDL20_VBELN "/>
<xsl:choose>
<xsl:when test="/ACTIS/G01/G07[#PACK_TYPE='OUTER']/E2EDT37[contains(E2EDT37_DELIVERIES, $current-delivery)]">
<xsl:call-template name="Create_Outer_PAC">
<xsl:with-param name="current-delivery" select=" $current-delivery "/>
</xsl:call-template>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</xsl:template>
<xsl:template name="Create_Outer_PAC">
<xsl:param name="current-delivery"/>
<xsl:message>In Create_Outer_PACK Delivery: <xsl:value-of select="$current-delivery"/></xsl:message>
<xsl:for-each select="/ACTIS/G01/G07/E2EDT37[E2EDT37_PACK_TYPE='OUTER'][contains(E2EDT37_DELIVERIES, $current-delivery)]">
<xsl:variable name="Pallet" select="current()"/>
<xsl:message>For each Outer_PAC : <xsl:value-of select="$Pallet/E2EDT37_EXIDV"/></xsl:message>
<xsl:for-each select="/ACTIS/G01/G07/E2EDT37[E2EDT37_PACK_TYPE='INNER'][E2EDT37_PARENT=$Pallet/E2EDT37_EXIDV][E2EDT37_DELIVERY=$current-delivery]/E2EDT37_KDMAT[not(.=preceding::E2EDT37_KDMAT)]">
<xsl:variable name="current-part" select="current()"/>
<xsl:message>For each E2EDT37_KDMAT : <xsl:value-of select="$current-part"/></xsl:message>
<xsl:message select="/ACTIS/G01/G07/E2EDT37[E2EDT37_PACK_TYPE='INNER'][E2EDT37_PARENT=$Pallet/E2EDT37_EXIDV][E2EDT37_DELIVERY=$current-delivery][E2EDT37_KDMAT=$current-part]/E2EDT37_VHILM_KU"/>
<xsl:for-each select="/ACTIS/G01/G07/E2EDT37[E2EDT37_PACK_TYPE='INNER'][E2EDT37_PARENT=$Pallet/E2EDT37_EXIDV][E2EDT37_DELIVERY=$current-delivery][E2EDT37_KDMAT=$current-part]/E2EDT37_VHILM_KU[not(.=preceding::E2EDT37_VHILM_KU)]">
<xsl:variable name="current-vhilm_ku" select="current()"/>
<xsl:message>For each E2EDT37_VHILM_KU: <xsl:value-of select="$current-vhilm_ku"/></xsl:message>
<xsl:for-each select="/ACTIS/G01/G07/E2EDT37[E2EDT37_PACK_TYPE='INNER'][E2EDT37_PARENT=$Pallet/E2EDT37_EXIDV][E2EDT37_DELIVERY=$current-delivery][E2EDT37_KDMAT=$current-part][E2EDT37_VHILM_KU=$current-vhilm_ku]/E2EDT37_QUANTITY[not(.=preceding::E2EDT37_QUANTITY)]">
<xsl:variable name="current-packqty" select="current()"/>
<xsl:message></xsl:message>
<xsl:message>For each E2EDT37_QUANTITY: <xsl:value-of select="$current-packqty"/></xsl:message>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Data
<?xml version="1.0" encoding="UTF-8"?>
<ACTIS>
<EDI_DC>
<EDI_DC_TABNAM>EDI_DC40</EDI_DC_TABNAM>
<EDI_DC_CREDAT>20190702</EDI_DC_CREDAT>
<EDI_DC_CRETIM>210325</EDI_DC_CRETIM>
<EDI_DC_SERIAL>20190702210323</EDI_DC_SERIAL>
</EDI_DC>
<G01>
<E2EDT20>
<E2EDT20_SEGNAM>E2EDT20002</E2EDT20_SEGNAM>
<E2EDT20_MANDT>100</E2EDT20_MANDT>
<E2EDT20_DOCNUM>0000004250699555</E2EDT20_DOCNUM>
<E2EDT20_SEGNUM>000001</E2EDT20_SEGNUM>
<E2EDT20_PSGNUM>000000</E2EDT20_PSGNUM>
<E2EDT20_HLEVEL>01</E2EDT20_HLEVEL>
<E2EDT20_TKNUM>0049409223</E2EDT20_TKNUM>
</E2EDT20>
<G07 PACK_TYPE="INNER" PARENT="505059227" CHILDREN="0" MIXED="0">
<E2EDT37 PACK_TYPE="INNER" PARENT="505059227" CHILDREN="0" MIXED="0">
<E2EDT37_SEGNAM>E2EDT37006</E2EDT37_SEGNAM>
<E2EDT37_MANDT>100</E2EDT37_MANDT>
<E2EDT37_DOCNUM>0000004250699555</E2EDT37_DOCNUM>
<E2EDT37_SEGNUM>000044</E2EDT37_SEGNUM>
<E2EDT37_PSGNUM>000001</E2EDT37_PSGNUM>
<E2EDT37_HLEVEL>02</E2EDT37_HLEVEL>
<E2EDT37_EXIDV>00000000000505755236</E2EDT37_EXIDV>
<E2EDT37_VHILM_KU>0000SON</E2EDT37_VHILM_KU>
<E2EDT37_PACK_TYPE>INNER</E2EDT37_PACK_TYPE>
<E2EDT37_CHILDREN>0</E2EDT37_CHILDREN>
<E2EDT37_PARENT>505059227</E2EDT37_PARENT>
<E2EDT37_DELIVERY>0037371519</E2EDT37_DELIVERY>
<E2EDT37_DELIVERY_POSITION>000010</E2EDT37_DELIVERY_POSITION>
<E2EDT37_QUANTITY>8500.000</E2EDT37_QUANTITY>
<E2EDT37_UOM>PCE</E2EDT37_UOM>
<E2EDT37_KDMAT>6561111</E2EDT37_KDMAT>
<E2EDT37_VBRST>1000</E2EDT37_VBRST>
</E2EDT37>
</G07>
<G07 PACK_TYPE="INNER" PARENT="505059227" CHILDREN="0" MIXED="0">
<E2EDT37 PACK_TYPE="INNER" PARENT="505059227" CHILDREN="0" MIXED="0">
<E2EDT37_SEGNAM>E2EDT37006</E2EDT37_SEGNAM>
<E2EDT37_MANDT>100</E2EDT37_MANDT>
<E2EDT37_DOCNUM>0000004250699555</E2EDT37_DOCNUM>
<E2EDT37_SEGNUM>000047</E2EDT37_SEGNUM>
<E2EDT37_PSGNUM>000001</E2EDT37_PSGNUM>
<E2EDT37_HLEVEL>02</E2EDT37_HLEVEL>
<E2EDT37_EXIDV>00000000000505755237</E2EDT37_EXIDV>
<E2EDT37_VHILM_KU>0000SON</E2EDT37_VHILM_KU>
<E2EDT37_PACK_TYPE>INNER</E2EDT37_PACK_TYPE>
<E2EDT37_CHILDREN>0</E2EDT37_CHILDREN>
<E2EDT37_PARENT>505059227</E2EDT37_PARENT>
<E2EDT37_DELIVERY>0037371484</E2EDT37_DELIVERY>
<E2EDT37_DELIVERY_POSITION>000010</E2EDT37_DELIVERY_POSITION>
<E2EDT37_QUANTITY>7000.000</E2EDT37_QUANTITY>
<E2EDT37_UOM>PCE</E2EDT37_UOM>
<E2EDT37_KDMAT>6561143</E2EDT37_KDMAT>
<E2EDT37_VBRST>1000</E2EDT37_VBRST>
</E2EDT37>
</G07>
<G07 PACK_TYPE="OUTER" CHILDREN="2" MIXED="1">
<E2EDT37 PACK_TYPE="OUTER" CHILDREN="2" MIXED="1">
<E2EDT37_SEGNAM>E2EDT37006</E2EDT37_SEGNAM>
<E2EDT37_MANDT>100</E2EDT37_MANDT>
<E2EDT37_DOCNUM>0000004250699555</E2EDT37_DOCNUM>
<E2EDT37_SEGNUM>000050</E2EDT37_SEGNUM>
<E2EDT37_PSGNUM>000001</E2EDT37_PSGNUM>
<E2EDT37_HLEVEL>02</E2EDT37_HLEVEL>
<E2EDT37_EXIDV>505059227</E2EDT37_EXIDV>
<E2EDT37_VHILM_KU>0000SON</E2EDT37_VHILM_KU>
<E2EDT37_CHILDREN>2</E2EDT37_CHILDREN>
<E2EDT37_CONTENTS>00000000000505755236:00000000000505755237:</E2EDT37_CONTENTS>
<E2EDT37_PACK_TYPE>OUTER</E2EDT37_PACK_TYPE>
<E2EDT37_DELIVERIES>0037371519 0037371484</E2EDT37_DELIVERIES>
</E2EDT37>
</G07>
<G16>
<E2EDL20>
<E2EDL20_SEGNAM>E2EDL20004</E2EDL20_SEGNAM>
<E2EDL20_MANDT>100</E2EDL20_MANDT>
<E2EDL20_DOCNUM>0000004250699555</E2EDL20_DOCNUM>
<E2EDL20_SEGNUM>000077</E2EDL20_SEGNUM>
<E2EDL20_PSGNUM>000001</E2EDL20_PSGNUM>
<E2EDL20_HLEVEL>02</E2EDL20_HLEVEL>
<E2EDL20_VBELN>0037371484</E2EDL20_VBELN>
<E2EDL20_VSTEL>0016</E2EDL20_VSTEL>
<E2EDL20_VKORG>0060</E2EDL20_VKORG>
<E2EDL20_VKBUR>EUR</E2EDL20_VKBUR>
<E2EDL20_LGNUM>D16</E2EDL20_LGNUM>
<E2EDL20_ABLAD>JAG01</E2EDL20_ABLAD>
<E2EDL20_INCO1>FCA</E2EDL20_INCO1>
<E2EDL20_INCO2>NÜRNBERG</E2EDL20_INCO2>
<E2EDL20_ROUTE>DES129</E2EDL20_ROUTE>
<E2EDL20_VSBED>ST</E2EDL20_VSBED>
<E2EDL20_BTGEW>107.000</E2EDL20_BTGEW>
<E2EDL20_NTGEW>107.000</E2EDL20_NTGEW>
<E2EDL20_GEWEI>KGM</E2EDL20_GEWEI>
<E2EDL20_VOLUM>1036.427</E2EDL20_VOLUM>
<E2EDL20_VOLEH>DMQ</E2EDL20_VOLEH>
<E2EDL20_ANZPK>00000</E2EDL20_ANZPK>
<E2EDL20_PARID>UNKNOWN</E2EDL20_PARID>
<E2EDL20_PODAT>20190702</E2EDL20_PODAT>
<E2EDL20_POTIM>210324</E2EDL20_POTIM>
</E2EDL20>
<G29>
<E2EDL24>
<E2EDL24_POSNR>000010</E2EDL24_POSNR>
<E2EDL24_KDMAT>6561143</E2EDL24_KDMAT>
<E2EDL24_LFIMG>7000.000</E2EDL24_LFIMG>
<E2EDL24_VRKME>PCE</E2EDL24_VRKME>
<E2EDL24_VBRST>1000</E2EDL24_VBRST>
<E2EDL24_KDMAT35>6561143</E2EDL24_KDMAT35>
<E2EDL24_POSEX>000000</E2EDL24_POSEX>
<E2EDL24_DELIVERY>0037371484</E2EDL24_DELIVERY>
<E2EDL24_PO>5500229851</E2EDL24_PO>
<E2EDL24_PO_DATE>20150612</E2EDL24_PO_DATE>
</E2EDL24>
</G29>
<G29>
<E2EDL24>
<E2EDL24_POSNR>900001</E2EDL24_POSNR>
<E2EDL24_KDMAT>0000SON</E2EDL24_KDMAT>
<E2EDL24_LFIMG>1.000</E2EDL24_LFIMG>
<E2EDL24_VRKME>PCE</E2EDL24_VRKME>
<E2EDL24_VBRST>1000</E2EDL24_VBRST>
<E2EDL24_KDMAT35>0000SON</E2EDL24_KDMAT35>
<E2EDL24_POSEX>000000</E2EDL24_POSEX>
<E2EDL24_DELIVERY>0037371484</E2EDL24_DELIVERY>
</E2EDL24>
</G29>
</G16>
<G16>
<E2EDL20>
<E2EDL20_SEGNAM>E2EDL20004</E2EDL20_SEGNAM>
<E2EDL20_MANDT>100</E2EDL20_MANDT>
<E2EDL20_DOCNUM>0000004250699555</E2EDL20_DOCNUM>
<E2EDL20_SEGNUM>000170</E2EDL20_SEGNUM>
<E2EDL20_PSGNUM>000001</E2EDL20_PSGNUM>
<E2EDL20_HLEVEL>02</E2EDL20_HLEVEL>
<E2EDL20_VBELN>0037371519</E2EDL20_VBELN>
<E2EDL20_VSTEL>0016</E2EDL20_VSTEL>
<E2EDL20_VKORG>0060</E2EDL20_VKORG>
<E2EDL20_VKBUR>EUR</E2EDL20_VKBUR>
<E2EDL20_LGNUM>D16</E2EDL20_LGNUM>
<E2EDL20_ABLAD>JAG01</E2EDL20_ABLAD>
<E2EDL20_INCO1>FCA</E2EDL20_INCO1>
<E2EDL20_INCO2>NÜRNBERG</E2EDL20_INCO2>
<E2EDL20_ROUTE>DES129</E2EDL20_ROUTE>
<E2EDL20_VSBED>ST</E2EDL20_VSBED>
<E2EDL20_BTGEW>140.600</E2EDL20_BTGEW>
<E2EDL20_NTGEW>127.500</E2EDL20_NTGEW>
<E2EDL20_GEWEI>KGM</E2EDL20_GEWEI>
<E2EDL20_VOLUM>42840.000</E2EDL20_VOLUM>
<E2EDL20_VOLEH>CMQ</E2EDL20_VOLEH>
<E2EDL20_ANZPK>00000</E2EDL20_ANZPK>
<E2EDL20_PARID>UNKNOWN</E2EDL20_PARID>
<E2EDL20_PODAT>20190702</E2EDL20_PODAT>
<E2EDL20_POTIM>210325</E2EDL20_POTIM>
</E2EDL20>
<G29>
<E2EDL24>
<E2EDL24_POSNR>000010</E2EDL24_POSNR>
<E2EDL24_KDMAT>6561111</E2EDL24_KDMAT>
<E2EDL24_LFIMG>8500.000</E2EDL24_LFIMG>
<E2EDL24_VRKME>PCE</E2EDL24_VRKME>
<E2EDL24_VBRST>1000</E2EDL24_VBRST>
<E2EDL24_KDMAT35>6561111</E2EDL24_KDMAT35>
<E2EDL24_POSEX>000000</E2EDL24_POSEX>
<E2EDL24_DELIVERY>0037371519</E2EDL24_DELIVERY>
<E2EDL24_PO>5500229848</E2EDL24_PO>
<E2EDL24_PO_DATE>20150612</E2EDL24_PO_DATE>
</E2EDL24>
</G29>
</G16>
</G01>
</ACTIS>
Resulting Output
1) In Create_Outer_PAC Delivery : 0037371484
2) For each Outer_PAC : 505059227
3) For each E2EDT37_KDMAT : 6561143 Good break here at unique KDMAT
I find and display a single matching VHILM_KU here but the next line that tries to loop at each VHILM_KU doesn't occur with the same Xpath as the xsl:message
<xsl:for-each select="/ACTIS/G01/G07/E2EDT37[E2EDT37_PACK_TYPE='INNER'][E2EDT37_PARENT=$Pallet/E2EDT37_EXIDV][E2EDT37_DELIVERY=$current-delivery][E2EDT37_KDMAT=$current-part]/E2EDT37_VHILM_KU[not(.=preceding::E2EDT37_VHILM_KU)]">
<E2EDT37_VHILM_KU>0000SON</E2EDT37_VHILM_KU>
No For each E2EDT37_VHILM_KU break on E2EDT37_VHILM_KU=0000SON
1) In Create_Outer_PAC Delivery : 0037371519
2) For each Outer_PAC : 505059227
3) For each E2EDT37_KDMAT : 6561111
<E2EDT37_VHILM_KU>0000SON</E2EDT37_VHILM_KU>
This one breaks as expected. You see we have an E2EDT37_VHILM_KU found with value 0000SON in the line above here.
I don't reach this message in the first for-each loop above although we also find and display the same E2EDT37_VHILM_KU of 0000SON.
We have two E2EDT37 segments with KDMAT values of 6561143 and 6561141. The first loop breaks at each unique KDMAT as expected.
4) For each E2EDT37_VHILM_KU : 0000SON
5) For each E2EDT37_QUANTITY : 8500.000
Is it valid to check for unique values with /E2EDT37_VHILM_KU[not(.=preceding::E2EDT37_VHILM_KU)] at the same time as limiting the resulting nodes with the predicates [E2EDT37_PACK_TYPE='INNER'][E2EDT37_PARENT=$Pallet/E2EDT37_EXIDV][E2EDT37_DELIVERY=$current-delivery][E2EDT37_KDMAT=$current-part]? I assume that's where I am wrong but the paradigm is not clear to me. The message output shows me the Xpath did find a single VHILM_KU. The next for-each statement with the same Xpath finds nothing.
Is that clearer or more confusing?

Related

Quick fix - schematron

I wrote a quickfix to insert a space between digit and string for example: 15MHz,20Hz
Schematron
<sch:pattern>
<sch:title>quick-fix</sch:title>
<sch:rule context="//text()">
<sch:report
test="matches(.,'(\d+)MHz') or matches(.,'(\d+)Hz')"
sqf:fix="groupfix" role="warning">Insert a space</sch:report>
<sqf:group id="groupfix">
<sqf:fix id="MHz-fix" use-when="contains(current(), 'MHz')">
<sqf:description>
<sqf:title>Insert space before MHz
</sqf:title>
</sqf:description>
<sqf:replace>
<xsl:analyze-string select="." regex="(\d+)MHz">
<xsl:matching-substring><xsl:value-of select="regex-group(1)"
/><xsl:value-of select="' MHz'"
/></xsl:matching-substring>
<xsl:non-matching-substring><xsl:value-of select="."
/></xsl:non-matching-substring>
</xsl:analyze-string>
</sqf:replace>
</sqf:fix>
<sqf:fix id="Hz-fix" use-when="contains(current(), 'Hz')">
<sqf:description>
<sqf:title>Insert space before Hz
</sqf:title>
</sqf:description>
<sqf:replace>
<xsl:analyze-string select="." regex="(\d+)Hz">
<xsl:matching-substring><xsl:value-of select="regex-group(1)"
/><xsl:value-of select="' Hz'"
/></xsl:matching-substring>
<xsl:non-matching-substring><xsl:value-of select="."
/></xsl:non-matching-substring>
</xsl:analyze-string>
</sqf:replace>
</sqf:fix>
</sqf:group>
</sch:rule>
</sch:pattern>
xml
<topic>
<p>15MHz</p>
</topic>
I am able to insert the space before MHz but the quick fix displays two options "Insert space before MHz" and "Insert space before Hz". I want only "Insert space before MHz" to be displayed.
Please help. Thanks
In stead of this:
<sqf:fix id="Hz-fix" use-when="contains(current(), 'Hz')">
do this:
<sqf:fix id="Hz-fix" use-when="matches(current(), '(\d+)Hz')">
Use in use-when also the matches function which checks for the given pattern.
Optional:
you can replace current() with . to save code.
In Oxygen you can use <sqf:stringReplace regex="(\d+)Hz" select="'$1 Hz'"/> instead of the complex <xsl:analyze-string>.

XSLT get array element by id

I have XSLT:
<xsl:template match="/">
<!--<FLC_OKVEDCODE>-->
<xsl:variable name="valArray" select="//NodeA | //NodeB | //NodeC"/>
<xsl:variable name="valResArray">
<result_value>TextA</result_value>
<result_value>TextB</result_value>
<result_value>TextC</result_value>
</xsl:variable>
<xsl:variable name="resArray" select="document('')//xsl:variable[#name= 'valResArray']/*"></xsl:variable>
<xsl:for-each select="$valArray">
<xsl:if test="string-length(normalize-space(text())) = 0">
<ERROR>
<Err1><xsl:value-of select="position()"></xsl:value-of></Err1>
<Err2><xsl:value-of select="$resArray[1]"></xsl:value-of></Err2>
<Err3><xsl:value-of select="$resArray[2]"></xsl:value-of></Err3>
<Err4><xsl:value-of select="$resArray[3]"></xsl:value-of></Err4>
<Err5><xsl:value-of select="$resArray[position()]"></xsl:value-of></Err5>
</ERROR>
</xsl:if>
</xsl:for-each>
<!--</FLC_>-->
</xsl:template>
It have to check NodeA, NodeB and NodeC if they are empty - create error XML. In my test NodeB is empty, but result is:
<ERROR>
<Err1>2</Err1>
<Err2>TextA</Err2>
<Err3>TextB</Err3>
<Err4>TextC</Err4>
<Err5>TextA</Err5>
</ERROR>
Why Err5 is TextA, if position() return 2 and $resArray[2] (printed at ) is TextB??
After that problem ate my brain, solution was very simple:
Adding:
<xsl:variable name="temppos" select="position()"></xsl:variable>
between Err4 and Err5. It looks like it automatically puts array as parameter for such functions as "position", and do it with closest array. So, "position()" of "resArray" was still 1, and that is why there was this result.
That is explanation that I guess. Still, I disappointed with handling arrays in XSLT.
Why Err5 is TextA, if position() return 2
Why do you think that position() returns 2? The truth is that the expression:
$resArray[position()]
means "all nodes of $resArray that have a non-zero (i.e. true) position". Which is true of all nodes of $resArray.
Therefore the expression:
<xsl:value-of select="$resArray[position()]"/>
will return the value of the first node of the returned node-set (i.e. TextA) in XSLT 1.0, and the values of all matching nodes (i.e. TextA TextB TextC) in XSLT 2.0.

XML XPath - Sub path

Using the following XML, in SQL Server how can I get a table of LineItemId,PetId(value),vetid(Value)? I'm stumped.
Basically, It should return:
255fa32c-dce6-4e7a-83a5-4b45f22f00fc 75866 12916
183dc279-53a6-45fc-9e75-57770582b6bc 34535 34546
From this XML:
<PurchaseOrder>
<OrderForms>
<OrderForm>
<LineItems>
<LineItem LineItemId="255fa32c-dce6-4e7a-83a5-4b45f22f00fc">
<WeaklyTypedProperties>
<WeaklyTypedProperty Name="petId" Value="75866" Type="String" />
<WeaklyTypedProperty Name="vetId" Value="12916" Type="String" />
</WeaklyTypedProperties>
</LineItem>
<LineItem LineItemId="183dc279-53a6-45fc-9e75-57770582b6bc">
<WeaklyTypedProperties>
<WeaklyTypedProperty Name="petId" Value="345345" Type="String" />
<WeaklyTypedProperty Name="vetId" Value="345346" Type="String" />
</WeaklyTypedProperties>
</LineItem>
</LineItems>
</OrderForm>
</OrderForms>
</PurchaseOrder>
I should state I have tried the following, but it gives blanks for petId and vetId:
SELECT
p.value('#LineItemId','NVARCHAR(100)')
,p.query('//PurchaseOrder/OrderForms/OrderForm[1]/LineItems/LineItem[1]/WeaklyTypedProperties/WeaklyTypedProperty[Name="petId"]')
,p.query('//PurchaseOrder/OrderForms/OrderForm[1]/LineItems/LineItem[1]/WeaklyTypedProperties/WeaklyTypedProperty[Name="vetid"]')
FROM
dbo.[PurchaseOrdersMarshalledData] pomd
CROSS APPLY pomd.[MarshalledData].nodes('//PurchaseOrder/OrderForms/OrderForm[1]/LineItems/LineItem') x(p)
Thanks!
SELECT
[LineItemId] = l.value('#LineItemId', 'nvarchar(100)'),
[PetId] = w.value('WeaklyTypedProperty[#Name="petId"][1]/#Value', 'int'),
[VetId] = w.value('WeaklyTypedProperty[#Name="vetId"][1]/#Value', 'int')
FROM dbo.[PurchaseOrdersMarshalledData] pomp
CROSS APPLY pomp.[MarshalledData].nodes('//PurchaseOrder/OrderForms/OrderForm[1]/LineItems/LineItem') LineItem(l)
CROSS APPLY l.nodes('WeaklyTypedProperties') WeaklyTypedProperty(w)
Haven't tried it... maybe the syntaxis is not 100% correct...
<xsl:for-each select="/PurcharseOrder/OrderForms/OrderForm/LineItems/LineItem"/>
<xsl:value-of select="#LineItemId"/>
<xsl:for-each select="WeaklyTypedProperties"/>
<xsl:value-of select="WeaklyTypedProperty/#Value"/>
</xsl:for-each>
</xsl:for-each>

Fuse ESB - Camel issue

We are trying to install a bundle using osgi in Fuse ESB 7.1.0.
Inside this bundle, in camel-context we are using like below:
<camelContext xmlns="http://camel.apache.org/schema/spring">
<endpoint uri="http://IPADDRESS:8080/LOB_Webservice/LOBSampleWebService?throwExceptionOnFailure=false" id="callLOBServer"/>
<route>
<from uri="cxf:bean:lobclient?dataFormat=MESSAGE"/>
<to uri="log:output"/>
<bean ref="enrichBean"/>
<to uri="xslt:etc/8.xsl"/>
<bean ref="enrichBean"/>
<to ref="callLOBServer"/>
<bean ref="enrichBean"/>
***<to uri="xslt:etc/3.xsl"/>***
<bean ref="enrichBean"/>
<to uri="xslt:etc/7.xsl"/>
<bean ref="enrichBean"/>
<to uri="log:output"/>
</route>
</camelContext>
The above 3.xsl is using XSLT 2.0.
When we try to install this, it is getting failed with below information:
15:11:23,047 | ERROR | ExtenderThread-4 | XsltErrorListener | 147 - org.apache.camel.camel-core - 2.10.0.fuse-71-047 | A location step was expected following the '/' or '//' token.; Line#: 8; Column#: 77
15:11:23,047 | ERROR | ExtenderThread-4 | ContextLoaderListener | 113 - org.springframework.osgi.extender - 1.2.1 | Application context refresh failed (OsgiBundleXmlApplicationContext(bundle=org.apache.camel.camel-example-cxf-proxy, config=osgibundle:/META-INF/spring/*.xml))
java.lang.StackOverflowError
at java.security.AccessController.doPrivileged(Native Method)[:1.7.0_07]
at org.osgi.framework.FrameworkUtil.getBundle(FrameworkUtil.java:208)[karaf.jar:2.3.0.fuse-71-047]
at org.ops4j.pax.logging.util.OsgiUtil.getBundleOrNull(OsgiUtil.java:114)[3:org.ops4j.pax.logging.pax-logging-service:1.7.0]
at org.apache.log4j.OsgiThrowableRenderer.getClassDetail(OsgiThrowableRenderer.java:148)[3:org.ops4j.pax.logging.pax-logging-service:1.7.0]
at org.apache.log4j.OsgiThrowableRenderer.formatElement(OsgiThrowableRenderer.java:135)[3:org.ops4j.pax.logging.pax-logging-service:1.7.0]
at org.apache.log4j.OsgiThrowableRenderer.doRender(OsgiThrowableRenderer.java:105)[3:org.ops4j.pax.logging.pax-logging-service:1.7.0]
at org.apache.log4j.OsgiThrowableRenderer.doRender(OsgiThrowableRenderer.java:52)[3:org.ops4j.pax.logging.pax-logging-service:1.7.0]
at org.apache.log4j.spi.ThrowableInformation.getThrowableStrRep(ThrowableInformation.java:89)[3:org.ops4j.pax.logging.pax-logging-service:1.7.0]
at org.apache.log4j.spi.LoggingEvent.getThrowableStrRep(LoggingEvent.java:413)[3:org.ops4j.pax.logging.pax-logging-service:1.7.0]
at org.apache.log4j.WriterAppender.subAppend(WriterAppender.java:313)[3:org.ops4j.pax.logging.pax-logging-service:1.7.0]
at org.apache.log4j.RollingFileAppender.subAppend(RollingFileAppender.java:276)[3:org.ops4j.pax.logging.pax-logging-service:1.7.0]
at org.apache.log4j.WriterAppender.append(WriterAppender.java:162)[3:org.ops4j.pax.logging.pax-logging-service:1.7.0]
at org.apache.log4j.AppenderSkeleton.doAppend(AppenderSkeleton.java:251)[3:org.ops4j.pax.logging.pax-logging-service:1.7.0]
at org.apache.log4j.helpers.AppenderAttachableImpl.appendLoopOnAppenders(AppenderAttachableImpl.java:66)[3:org.ops4j.pax.logging.pax-logging-service:1.7.0]
at org.apache.log4j.Category.callAppenders(Category.java:193)[4:org.ops4j.pax.logging.pax-logging-api:1.7.0]
at org.apache.log4j.Category.forcedLog(Category.java:365)[4:org.ops4j.pax.logging.pax-logging-api:1.7.0]
at org.apache.log4j.Category.log(Category.java:772)[4:org.ops4j.pax.logging.pax-logging-api:1.7.0]
at org.ops4j.pax.logging.service.internal.PaxLoggerImpl.error(PaxLoggerImpl.java:159)[3:org.ops4j.pax.logging.pax-logging-service:1.7.0]
at org.ops4j.pax.logging.internal.TrackingLogger.error(TrackingLogger.java:96)[3:org.ops4j.pax.logging.pax-logging-service:1.7.0]
at org.ops4j.pax.logging.slf4j.Slf4jLogger.error(Slf4jLogger.java:911)[4:org.ops4j.pax.logging.pax-logging-api:1.7.0]
at org.apache.camel.builder.xml.XsltErrorListener.fatalError(XsltErrorListener.java:44)[147:org.apache.camel.camel-core:2.10.0.fuse-71-047]
at org.apache.xpath.compiler.XPathParser.error(XPathParser.java:614)[:]
at org.apache.xpath.compiler.XPathParser.RelativeLocationPath(XPathParser.java:1639)[:]
Here is the content of 3.xsl also.
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="return">
<xsl:copy>
<xsl:apply-templates select="#*|node()"/>
<ordertotal>
<xsl:value-of select="sum(orderDetails/(itemPrice * itemQty))"/>
</ordertotal>
</xsl:copy>
</xsl:template>
<xsl:template match="#*|node()">
<xsl:copy>
<xsl:apply-templates select="#*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
But when we try to replace 3.xsl with equivalent XSLT 1.0 functionality, its working fine.
As part of requirements, we need to work with XSLT 2.0 only.
Can someone please help? Thanks.
Latest stack trace..
16:06:46,210 | ERROR | ExtenderThread-2 | XsltErrorListener | 147 - org.apache.camel.camel-core - 2.10.0.fuse-71-047 | A location step was expected following the '/' or '//' token.; Line#: 8; Column#: 78
16:06:46,210 | ERROR | ExtenderThread-2 | ContextLoaderListener | 113 - org.springframework.osgi.extender - 1.2.1 | Application context refresh failed (OsgiBundleXmlApplicationContext(bundle=org.apache.camel.camel-example-cxf-proxy, config=osgibundle:/META-INF/spring/*.xml))
java.lang.StackOverflowError
at java.util.concurrent.ConcurrentHashMap.hash(ConcurrentHashMap.java:332)[:1.7.0_07]
at java.util.concurrent.ConcurrentHashMap.putIfAbsent(ConcurrentHashMap.java:1144)[:1.7.0_07]
at java.lang.ClassLoader.getClassLoadingLock(ClassLoader.java:462)[:1.7.0_07]
at java.lang.ClassLoader.loadClass(ClassLoader.java:403)[:1.7.0_07]
at java.lang.ClassLoader.loadClass(ClassLoader.java:410)[:1.7.0_07]
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)[:1.7.0_07]
at java.lang.ClassLoader.loadClass(ClassLoader.java:410)[:1.7.0_07]
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)[:1.7.0_07]
at org.apache.felix.framework.ExtensionManager$ExtensionManagerWiring.getClassByDelegation(ExtensionManager.java:873)
at org.apache.felix.framework.BundleWiringImpl.searchImports(BundleWiringImpl.java:1520)
at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1466)
at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:75)
at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1882)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)[:1.7.0_07]
at org.apache.felix.framework.Felix.loadBundleClass(Felix.java:1814)
at org.apache.felix.framework.BundleImpl.loadClass(BundleImpl.java:929)
at org.springframework.osgi.util.BundleDelegatingClassLoader.findClass(BundleDelegatingClassLoader.java:99)[114:org.springframework.osgi.core:1.2.1]
at org.springframework.osgi.util.BundleDelegatingClassLoader.loadClass(BundleDelegatingClassLoader.java:156)[114:org.springframework.osgi.core:1.2.1]
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)[:1.7.0_07]
at org.ops4j.pax.logging.util.OsgiUtil.loadClass(OsgiUtil.java:99)[3:org.ops4j.pax.logging.pax-logging-service:1.7.0]
at org.apache.log4j.OsgiThrowableRenderer.findClass(OsgiThrowableRenderer.java:221)[3:org.ops4j.pax.logging.pax-logging-service:1.7.0]
at org.apache.log4j.OsgiThrowableRenderer.formatElement(OsgiThrowableRenderer.java:134)[3:org.ops4j.pax.logging.pax-logging-service:1.7.0]
at org.apache.log4j.OsgiThrowableRenderer.doRender(OsgiThrowableRenderer.java:105)[3:org.ops4j.pax.logging.pax-logging-service:1.7.0]
at org.apache.log4j.OsgiThrowableRenderer.doRender(OsgiThrowableRenderer.java:52)[3:org.ops4j.pax.logging.pax-logging-service:1.7.0]
at org.apache.log4j.spi.ThrowableInformation.getThrowableStrRep(ThrowableInformation.java:89)[3:org.ops4j.pax.logging.pax-logging-service:1.7.0]
at org.apache.log4j.spi.LoggingEvent.getThrowableStrRep(LoggingEvent.java:413)[3:org.ops4j.pax.logging.pax-logging-service:1.7.0]
at org.apache.log4j.WriterAppender.subAppend(WriterAppender.java:313)[3:org.ops4j.pax.logging.pax-logging-service:1.7.0]
at org.apache.log4j.RollingFileAppender.subAppend(RollingFileAppender.java:276)[3:org.ops4j.pax.logging.pax-logging-service:1.7.0]
at org.apache.log4j.WriterAppender.append(WriterAppender.java:162)[3:org.ops4j.pax.logging.pax-logging-service:1.7.0]
at org.apache.log4j.AppenderSkeleton.doAppend(AppenderSkeleton.java:251)[3:org.ops4j.pax.logging.pax-logging-service:1.7.0]
at org.apache.log4j.helpers.AppenderAttachableImpl.appendLoopOnAppenders(AppenderAttachableImpl.java:66)[3:org.ops4j.pax.logging.pax-logging-service:1.7.0]
at org.apache.log4j.Category.callAppenders(Category.java:193)[4:org.ops4j.pax.logging.pax-logging-api:1.7.0]
at org.apache.log4j.Category.forcedLog(Category.java:365)[4:org.ops4j.pax.logging.pax-logging-api:1.7.0]
at org.apache.log4j.Category.log(Category.java:772)[4:org.ops4j.pax.logging.pax-logging-api:1.7.0]
at org.ops4j.pax.logging.service.internal.PaxLoggerImpl.error(PaxLoggerImpl.java:159)[3:org.ops4j.pax.logging.pax-logging-service:1.7.0]
at org.ops4j.pax.logging.internal.TrackingLogger.error(TrackingLogger.java:96)[3:org.ops4j.pax.logging.pax-logging-service:1.7.0]
at org.ops4j.pax.logging.slf4j.Slf4jLogger.error(Slf4jLogger.java:911)[4:org.ops4j.pax.logging.pax-logging-api:1.7.0]
at org.apache.camel.builder.xml.XsltErrorListener.fatalError(XsltErrorListener.java:44)[147:org.apache.camel.camel-core:2.10.0.fuse-71-047]
at org.apache.xpath.compiler.XPathParser.error(XPathParser.java:614)[:]
at org.apache.xpath.compiler.XPathParser.RelativeLocationPath(XPathParser.java:1639)[:]
at org.apache.xpath.compiler.XPathParser.LocationPath(XPathParser.java:1597)[:]
at org.apache.xpath.compiler.XPathParser.PathExpr(XPathParser.java:1317)[:]
at org.apache.xpath.compiler.XPathParser.UnionExpr(XPathParser.java:1236)[:]
at org.apache.xpath.compiler.XPathParser.UnaryExpr(XPathParser.java:1142)[:]
at org.apache.xpath.compiler.XPathParser.MultiplicativeExpr(XPathParser.java:1063)[:]
Input XML file
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns2:fetchOrderListResponse xmlns:ns2="http://impl.lob.wipro.com/">
<return>
<customerOrderNumber>1</customerOrderNumber>
<orderDetails>
<itemPrice>50.0</itemPrice>
<itemQty>2</itemQty>
<itemUnit>0</itemUnit>
<orderDetailsId>37516016-D71B-4790-951F-55D00B0CC159</orderDetailsId>
<camelAddedDtlField>0.1</camelAddedDtlField>
</orderDetails>
<orderDetails>
<itemPrice>39.0</itemPrice>
<itemQty>3</itemQty>
<itemUnit>0</itemUnit>
<orderDetailsId>6095ABC7-0D0D-4B2E-92E5-80F24E9092B8</orderDetailsId>
<camelAddedDtlField>0.1</camelAddedDtlField>
</orderDetails>
<orderId>84EC371D-40CA-455E-A0FA-7EA733E9BFD3</orderId>
<ordertotal>0.0</ordertotal>
<camelAddedHdrField>0.0</camelAddedHdrField>
</return>
<return>
<customerOrderNumber>1</customerOrderNumber>
<orderId>54712493-2172-4ADB-814B-BC7AA0BB72C3</orderId>
<ordertotal>0.0</ordertotal>
<camelAddedHdrField>0.0</camelAddedHdrField>
</return>
<return>
<customerOrderNumber>1</customerOrderNumber>
<deliverydate>2013-02-06T00:00:00+05:30</deliverydate>
<orderDetails>
<itemPrice>565.0</itemPrice>
<itemQty>1</itemQty>
<itemUnit>0</itemUnit>
<orderDetailsId>9A5030BE-F95F-4C62-B5A2-41FF85423218</orderDetailsId>
<camelAddedDtlField>0.1</camelAddedDtlField>
</orderDetails>
<orderDetails>
<itemPrice>4.0</itemPrice>
<itemQty>90</itemQty>
<itemUnit>0</itemUnit>
<orderDetailsId>65A8B3BE-D407-43D8-8754-EA1E26AA56E4</orderDetailsId>
<camelAddedDtlField>0.1</camelAddedDtlField>
</orderDetails>
<orderId>0BDCB222-0117-47A9-8813-DF03A1D19E5E</orderId>
<ordertotal>0.0</ordertotal>
<camelAddedHdrField>0.0</camelAddedHdrField>
</return>
<return>
<customerOrderNumber>1</customerOrderNumber>
<orderId>8E4220DC-884B-47BC-A565-E26B80BA5249</orderId>
<ordertotal>0.0</ordertotal>
<camelAddedHdrField>0.0</camelAddedHdrField>
</return>
<return>
<customerOrderNumber>1</customerOrderNumber>
<deliverydate>2013-02-06T00:00:00+05:30</deliverydate>
<orderDetails>
<itemPrice>10.0</itemPrice>
<itemQty>4</itemQty>
<itemUnit>0</itemUnit>
<orderDetailsId>5A2DF895-BB0F-4039-80DB-F44CED31697B</orderDetailsId>
<camelAddedDtlField>0.1</camelAddedDtlField>
</orderDetails>
<orderDetails>
<itemPrice>20.0</itemPrice>
<itemQty>3</itemQty>
<itemUnit>0</itemUnit>
<orderDetailsId>8034FBF4-B573-4B19-BDF5-FAF6C4247A55</orderDetailsId>
<camelAddedDtlField>0.1</camelAddedDtlField>
</orderDetails>
<orderId>60161E3E-3C4A-4CE6-AAC3-E4D2BC240046</orderId>
<ordertotal>0.0</ordertotal>
<camelAddedHdrField>0.0</camelAddedHdrField>
</return>
</ns2:fetchOrderListResponse>
</soap:Body>
</soap:Envelope>
And the XSLT is as follows:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="#*|node()">
<xsl:copy>
<xsl:apply-templates select="#*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="ordertotal">
<xsl:copy>
<xsl:value-of select="sum(../orderDetails/(itemPrice*itemQty))" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
output expected..
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns2:fetchOrderListResponse xmlns:ns2="http://impl.lob.wipro.com/">
<return>
<customerOrderNumber>1</customerOrderNumber>
<orderDetails>
<itemPrice>50.0</itemPrice>
<itemQty>2</itemQty>
<itemUnit>0</itemUnit>
<orderDetailsId>37516016-D71B-4790-951F-55D00B0CC159</orderDetailsId>
<camelAddedDtlField>0.1</camelAddedDtlField>
</orderDetails>
<orderDetails>
<itemPrice>39.0</itemPrice>
<itemQty>3</itemQty>
<itemUnit>0</itemUnit>
<orderDetailsId>6095ABC7-0D0D-4B2E-92E5-80F24E9092B8</orderDetailsId>
<camelAddedDtlField>0.1</camelAddedDtlField>
</orderDetails>
<orderId>84EC371D-40CA-455E-A0FA-7EA733E9BFD3</orderId>
<ordertotal>217</ordertotal>
<camelAddedHdrField>0.0</camelAddedHdrField>
</return>
<return>
<customerOrderNumber>1</customerOrderNumber>
<orderId>54712493-2172-4ADB-814B-BC7AA0BB72C3</orderId>
<ordertotal>0</ordertotal>
<camelAddedHdrField>0.0</camelAddedHdrField>
</return>
<return>
<customerOrderNumber>1</customerOrderNumber>
<deliverydate>2013-02-06T00:00:00+05:30</deliverydate>
<orderDetails>
<itemPrice>565.0</itemPrice>
<itemQty>1</itemQty>
<itemUnit>0</itemUnit>
<orderDetailsId>9A5030BE-F95F-4C62-B5A2-41FF85423218</orderDetailsId>
<camelAddedDtlField>0.1</camelAddedDtlField>
</orderDetails>
<orderDetails>
<itemPrice>4.0</itemPrice>
<itemQty>90</itemQty>
<itemUnit>0</itemUnit>
<orderDetailsId>65A8B3BE-D407-43D8-8754-EA1E26AA56E4</orderDetailsId>
<camelAddedDtlField>0.1</camelAddedDtlField>
</orderDetails>
<orderId>0BDCB222-0117-47A9-8813-DF03A1D19E5E</orderId>
<ordertotal>925</ordertotal>
<camelAddedHdrField>0.0</camelAddedHdrField>
</return>
<return>
<customerOrderNumber>1</customerOrderNumber>
<orderId>8E4220DC-884B-47BC-A565-E26B80BA5249</orderId>
<ordertotal>0</ordertotal>
<camelAddedHdrField>0.0</camelAddedHdrField>
</return>
<return>
<customerOrderNumber>1</customerOrderNumber>
<deliverydate>2013-02-06T00:00:00+05:30</deliverydate>
<orderDetails>
<itemPrice>10.0</itemPrice>
<itemQty>4</itemQty>
<itemUnit>0</itemUnit>
<orderDetailsId>5A2DF895-BB0F-4039-80DB-F44CED31697B</orderDetailsId>
<camelAddedDtlField>0.1</camelAddedDtlField>
</orderDetails>
<orderDetails>
<itemPrice>20.0</itemPrice>
<itemQty>3</itemQty>
<itemUnit>0</itemUnit>
<orderDetailsId>8034FBF4-B573-4B19-BDF5-FAF6C4247A55</orderDetailsId>
<camelAddedDtlField>0.1</camelAddedDtlField>
</orderDetails>
<orderId>60161E3E-3C4A-4CE6-AAC3-E4D2BC240046</orderId>
<ordertotal>100</ordertotal>
<camelAddedHdrField>0.0</camelAddedHdrField>
</return>
</ns2:fetchOrderListResponse>
</soap:Body>
</soap:Envelope>
From the logs..(getting printed repeatedly..)
16:06:45,883 | ERROR | ExtenderThread-2 | XsltErrorListener | 147 - org.apache.camel.camel-core - 2.10.0.fuse-71-047 | A location step was expected following the '/' or '//' token.; Line#: 8; Column#: 78
javax.xml.transform.TransformerException: A location step was expected following the '/' or '//' token.
at org.apache.xpath.compiler.XPathParser.error(XPathParser.java:610)[:]
at org.apache.xpath.compiler.XPathParser.RelativeLocationPath(XPathParser.java:1639)[:]
at org.apache.xpath.compiler.XPathParser.LocationPath(XPathParser.java:1597)[:]
at org.apache.xpath.compiler.XPathParser.PathExpr(XPathParser.java:1317)[:]
at org.apache.xpath.compiler.XPathParser.UnionExpr(XPathParser.java:1236)[:]
at org.apache.xpath.compiler.XPathParser.UnaryExpr(XPathParser.java:1142)[:]
at org.apache.xpath.compiler.XPathParser.MultiplicativeExpr(XPathParser.java:1063)[:]
at org.apache.xpath.compiler.XPathParser.AdditiveExpr(XPathParser.java:1005)[:]
at org.apache.xpath.compiler.XPathParser.RelationalExpr(XPathParser.java:930)[:]
at org.apache.xpath.compiler.XPathParser.EqualityExpr(XPathParser.java:870)[:]
at org.apache.xpath.compiler.XPathParser.AndExpr(XPathParser.java:834)[:]
at org.apache.xpath.compiler.XPathParser.OrExpr(XPathParser.java:807)[:]
at org.apache.xpath.compiler.XPathParser.Expr(XPathParser.java:790)[:]
at org.apache.xpath.compiler.XPathParser.Argument(XPathParser.java:1469)[:]
at org.apache.xpath.compiler.XPathParser.FunctionCall(XPathParser.java:1537)[:]
at org.apache.xpath.compiler.XPathParser.PrimaryExpr(XPathParser.java:1446)[:]
at org.apache.xpath.compiler.XPathParser.FilterExpr(XPathParser.java:1345)[:]
at org.apache.xpath.compiler.XPathParser.PathExpr(XPathParser.java:1278)[:]
at org.apache.xpath.compiler.XPathParser.UnionExpr(XPathParser.java:1236)[:]
at org.apache.xpath.compiler.XPathParser.UnaryExpr(XPathParser.java:1142)[:]
at org.apache.xpath.compiler.XPathParser.MultiplicativeExpr(XPathParser.java:1063)[:]
at org.apache.xpath.compiler.XPathParser.AdditiveExpr(XPathParser.java:1005)[:]
at org.apache.xpath.compiler.XPathParser.RelationalExpr(XPathParser.java:930)[:]
at org.apache.xpath.compiler.XPathParser.EqualityExpr(XPathParser.java:870)[:]
at org.apache.xpath.compiler.XPathParser.AndExpr(XPathParser.java:834)[:]
at org.apache.xpath.compiler.XPathParser.OrExpr(XPathParser.java:807)[:]
at org.apache.xpath.compiler.XPathParser.Expr(XPathParser.java:790)[:]
at org.apache.xpath.compiler.XPathParser.initXPath(XPathParser.java:129)[:]
at org.apache.xpath.compiler.XPathParser.initXPath(XPathParser.java:157)[:]
at org.apache.xpath.compiler.XPathParser.initXPath(XPathParser.java:157)[:]
at org.apache.xpath.compiler.XPathParser.initXPath(XPathParser.java:157)[:]
at org.apache.xpath.compiler.XPathParser.initXPath(XPathParser.java:157)[:]
at org.apache.xpath.compiler.XPathParser.initXPath(XPathParser.java:157)[:]
at org.apache.xpath.compiler.XPathParser.initXPath(XPathParser.java:157)[:]
at org.apache.xpath.compiler.XPathParser.initXPath(XPathParser.java:157)[:]
at org.apache.xpath.compiler.XPathParser.initXPath(XPathParser.java:157)[:]
at org.apache.xpath.compiler.XPathParser.initXPath(XPathParser.java:157)[:]
at org.apache.xpath.compiler.XPathParser.initXPath(XPathParser.java:157)[:]
Just in case, if with Karaf + Apache camel you are getting error for XSLT 2.0 such as one mentioned below, simply force camel xslt component to use saxon (camel-saxon) instead of default from the JDK.
This could also occur if you create new nodes in karaf 4.x+ and with root node same xslt component could work but new nodes will try to pick xslt processor from JDK.
Problem (Error Sample):
javax.xml.transform.TransformerConfigurationException: Error checking type of the expression 'funcall(current-dateTime, [])'.
Solution (Example):
<to uri="xslt:transformers/XSLT-Mappers/CustomerService-Response.xsl?saxon=true" />

xsl iterate through list of alphabet

I need to iterate through the alphabet a-z, and for each one, print the letter, and then place some code that i already have working to display all items in my database that begin with that letter. Currently, i'm using a select to retrieve the first letter of all the item names which i display. However, the requirement is to display all letters, and then show 'no items to display' where there are no items. So, i can no longer use my select, which only returns the letters that have items.
How can I do this, without hardcoding each letter, and then calling my template 26 times after each one?
This transformation:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:my="my:my" >
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:key name="kItemBy1stLetter" match="item"
use="substring(.,1,1)"/>
<xsl:variable name="vDoc" select="/"/>
<xsl:variable name="vAlphabet" select=
"'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"
/>
<my:message>No items found.</my:message>
<xsl:variable name="vMessage" select="document('')/*/my:message"/>
<xsl:template match="/">
<xsl:for-each select=
"(document('')//node()|document('')//#*|document('')//namespace::*)
[ not(position() > 26)]
">
<xsl:variable name="vcurLetter" select=
"substring($vAlphabet, position(), 1)"/>
<xsl:for-each select="$vDoc">
<xsl:variable name="vSearchResult" select=
"key('kItemBy1stLetter', $vcurLetter)"/>
<xsl:value-of select="concat('
',$vcurLetter, ':
')"/>
<xsl:copy-of select="$vSearchResult | $vMessage[not($vSearchResult)]/text()"/>
</xsl:for-each>
<xsl:text>
</xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
when applied on this XML document (playing the role of "database"):
<database>
<item>Bicycles</item>
<item>Computers</item>
<item>Cars</item>
<item>Forks</item>
<item>Gellato</item>
<item>Hypervehicles</item>
<item>Ichtiosaurs</item>
<item>Jobs</item>
<item>Knots</item>
<item>Lens</item>
<item>Miracles</item>
<item>Notes</item>
</database>
produces the wanted result:
A:
No items found.
B:
<item>Bicycles</item>
C:
<item>Computers</item>
<item>Cars</item>
D:
No items found.
E:
No items found.
F:
<item>Forks</item>
G:
<item>Gellato</item>
H:
<item>Hypervehicles</item>
I:
<item>Ichtiosaurs</item>
J:
<item>Jobs</item>
K:
<item>Knots</item>
L:
<item>Lens</item>
M:
<item>Miracles</item>
N:
<item>Notes</item>
O:
No items found.
P:
No items found.
Q:
No items found.
R:
No items found.
S:
No items found.
T:
No items found.
U:
No items found.
V:
No items found.
W:
No items found.
X:
No items found.
Y:
No items found.
Z:
No items found.

Resources