Formatting an value array in xslt 1.0 - arrays

Could any good soul help me in the situation below?
I have this xml below that some fields are an array and I need to take the Value of these fields and concatenate separated by comma in xslt 1.0
Input XML
< io>
< key name="PeriodoInicial" value="2020-08-01"/ >
< key name="PeriodoFinal" value="2020-08-04"/ >
< key name="PartNumber" value="LIC-CUCM-12X-ESS"/>
< key name="NumeroProposta" value="34887"/>
< key name="CnpjCliente" value="59.285.411/0001-13"/>
< key name="NomeCliente" value="BANCO PAN S.A."/>
< key name="PO" value="1"/>
< key name="SO" value="2"/>
< key name="ShipmentId" value="12345"/>
< key name="CodigoTipoProduto" value="100"/>
< key name="CodigoTipoProduto" value="103"/>
< key name="CodigoFilial" value="1"/>
< key name="CodigoFilial" value="3"/>
< key name="CodigoVendedor" value="34"/>
< key name="CodigoVendedor" value="37"/>
< key name="CodigoVendedor" value="38"/>
< /io>
How do I expect the array values ​​to exit
< out>
< CodigoTipoProduto>100.103< /CodigoTipoProduto>
< CodigoFilial>1.3< /CodigoFilial>
< CodigoVendedor>34,37,38< /CodigoVendedor>
< /out>

You can use this XSLT-1.0 stylesheet:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output indent="yes"/>
<xsl:variable name="delimiter" select="'.'"/>
<xsl:template match="/io">
<out>
<CodigoTipoProduto><xsl:for-each select="key[#name='CodigoTipoProduto']"><xsl:value-of select="#value" /><xsl:if test="position() != last()"><xsl:value-of select="$delimiter" /></xsl:if></xsl:for-each></CodigoTipoProduto>
<CodigoFilial><xsl:for-each select="key[#name='CodigoFilial']"><xsl:value-of select="#value" /><xsl:if test="position() != last()"><xsl:value-of select="$delimiter" /></xsl:if></xsl:for-each></CodigoFilial>
<CodigoVendedor><xsl:for-each select="key[#name='CodigoVendedor']"><xsl:value-of select="#value" /><xsl:if test="position() != last()"><xsl:value-of select="$delimiter" /></xsl:if></xsl:for-each></CodigoVendedor>
</out>
</xsl:template>
</xsl:stylesheet>
Its result is:
<?xml version="1.0"?>
<out>
<CodigoTipoProduto>100.103</CodigoTipoProduto>
<CodigoFilial>1.3</CodigoFilial>
<CodigoVendedor>34.37.38</CodigoVendedor>
</out>

Related

XSL looping is not occurring properly at each level

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?

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>

solr version 4.1 PostingsSolrHighlighter feature not works

Now am doing analyzing on solr 4.1 version .In which,new Feature "SOLR-4271: Add support for PostingsHighlighter." has been given.
From the following link, http://lucene.apache.org/solr/4_1_0/solr-core/org/apache/solr/highlight/PostingsSolrHighlighter.html I found how to configure PostingHighlighter.
So I configured my PostingHighLighter as follows,
< searchComponent class="solr.HighlightComponent" name="highlight">
< highlighting class="org.apache.solr.highlight.PostingsSolrHighlighter"
preTag="<em_testing>"
postTag="</em_testing>"
ellipsis="... "
/>
< /searchComponent>
I used the following query to test highlighter;
solr/collection1/query?q=electronics&shard.keys=customerB!&wt=xml&hl=true&hl.fl=cat
But my result was, following one
< lst name="highlighting">
< lst name="F8V7067-APL-KIT">
< arr name="cat">
< str>
< em>electronics< /em>
< /str>
< /arr>
The expected result is < em_testing> instead of < em>.
So Whats wrong with my configuration or what is the actual use of PostingSolrHighlighter.

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