xsl-list
[Top] [All Lists]

Re: [xsl] Re: Comma concatenation for all unique node value based on Sibling

2007-03-31 05:18:52
Please try (or adapt it) this 1.0 stylesheet:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0">

<xsl:output method="text" />

<xsl:key name="by-product-number" match="LINE_ITEM[CUST_MSG = 'Y']"
use="PRODUCT_NUMBER" />

<xsl:template match="/">
  <xsl:for-each select="//LINE_ITEM[CUST_MSG = 'Y'][generate-id() =
generate-id(key('by-product-number', PRODUCT_NUMBER)[1])]">
    <xsl:value-of select="PRODUCT_NUMBER" />
    <xsl:if test="position() &lt; last()-1"><xsl:text>, </xsl:text></xsl:if>
    <xsl:if test="position()=last()-1"><xsl:text> and </xsl:text></xsl:if>
    <xsl:if test="position()=last()"><xsl:text>.</xsl:text></xsl:if>
  </xsl:for-each>
</xsl:template>

</xsl:stylesheet>

I suspect, your xsl:key definition would need changing. But without
seeing your complete code, it's difficult to guess.

On 3/31/07, Senthilkumaravelan K <skumaravelan(_at_)googlemail(_dot_)com> wrote:
Hi ,
I am using XSLT 1.0 and
I have tried the mentioned logic
<xsl:variable name="itemsOfthisProduct" select="//LINE_ITEM"/>
<!--<xsl:value-of
select="count($itemsOfthisProduct/PRODUCT_NUMBER[generate-id() =
generate-id(key('getUniqueData',.))])"/>
<xsl:for-each select="$itemsOfthisProduct/PRODUCT_NUMBER[generate-id()
= generate-id(key('getUniqueData',.))]"> -->
<!--<xsl:for-each
select="//SAP_PRODUCT_NUMBER[not(.=preceding::SAP_PRODUCT_NUMBER)][following-sibling:CUST_MSG=
'Y']"> -->
<xsl:for-each select="$itemsOfthisProduct/PRODUCT_NUMBER[generate-id()
= generate-id(key('getUniqueData',.))][following-sibling::CUST_WARN[1]=
'Y']">
<!--<xsl:if test="position() &gt; 1"><xsl:text>, </xsl:text></xsl:if>-->
<xsl:value-of select="./PRODUCT_NUMBER"/>
<xsl:if test="position() &lt; last()-1"><xsl:text>, </xsl:text></xsl:if>
<xsl:if test="position()=last()-1"><xsl:text> and </xsl:text></xsl:if>
<xsl:if test="position()=last()"><xsl:text>.</xsl:text></xsl:if>
</xsl:for-each>

It works on most of the cases
It is not showing the If the same product number first one with "Y"
and second one with "N" and it is ignoring  it.
How I could make it display it?
Any suggestions !!!
Thanks,
Senthil
On 3/30/07, Mukul Gandhi <gandhi(_dot_)mukul(_at_)gmail(_dot_)com> wrote:
> With XSLT 2.0, you can do as following:
>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; 
version="2.0">
>
>  <xsl:output method="text" />
>
>  <xsl:template match="/">
>     <xsl:value-of
> select="distinct-values(//PRODUCT_NUMBER[following-sibling::CUST_MSG[1]
> = 'Y'])" separator="," />
>  </xsl:template>
>
> </xsl:stylesheet>
>
> You could adapt the idea to suit your requirement.
>
> On 3/30/07, Senthilkumaravelan K <skumaravelan(_at_)googlemail(_dot_)com> 
wrote:
> > Hi ,
> > Is there anyway I could select all the unique PRODUCT_NUMBER with
> > their sibling node CUST_MSG=Y in a for loop so that i can concatenate
> > comma.if it is more than one .
> > Please help me this .
> > Thanks,
> > Senthil
> > On 3/29/07, Senthilkumaravelan K <skumaravelan(_at_)googlemail(_dot_)com> 
wrote:
> > > Hi
> > > <LINE_ITEMS>
> > > <LINE_ITEM>
> > > <PRODUCT_NUMBER>1</PRODUCT_NUMBER>
> > > <CUST_MSG>Y</CUST_MSG>
> > > </LINE_ITEM>
> > > <LINE_ITEM>
> > > <PRODUCT_NUMBER>1</PRODUCT_NUMBER>
> > > <CUST_MSG>Y</CUST_MSG>
> > > </LINE_ITEM>
> > > <LINE_ITEM>
> > > <PRODUCT_NUMBER>1</PRODUCT_NUMBER>
> > > <CUST_MSG>Y</CUST_MSG>
> > > </LINE_ITEM>
> > > <LINE_ITEM>
> > > <PRODUCT_NUMBER>2</PRODUCT_NUMBER>
> > > <CUST_MSG>N</CUST_MSG>
> > > </LINE_ITEM>
> > > </LINE_ITEMS>
> > >
> > > My expected out is
> > > <products>1 and 2.
> > > depends on the CUST_MSG value I need to concatenate "," and respectively.
> > >
> > > Thanks,
> > > Senthil


--
Regards,
Mukul Gandhi

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--