• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

concat() function

 
Shoba Ramachandran
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Is this a correct syntax to concat values.
<xsl:value-of select="concat(/item/description, ' is the description of part number ', /item/part-number)"/>
for this xml
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="order.xsl"?>
<order number="312597">
<date>2000/1/1</date>
<!-- this is the customer A-->
<customer id="216A">Company A</customer>
<item>
<part-number warehouse="Warehouse 11">E16-25A</part-number>
<description>Production-class widget</description>
<quantity>16</quantity>
</item>
<!-- this is the customer B-->
<customer id="216B">Company B</customer>
<item>
<part-number warehouse="Warehouse 12">E16-25B</part-number>
<description>Production-class widgetA</description>
<quantity>20</quantity>
</item>
</order>
Thanks
Shoba
 
John Wetherbie
Rancher
Posts: 1449
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks OK.
Does the output you get look like Production-class widget is the description of part number E16-25A?
[ May 06, 2002: Message edited by: John Wetherbie ]
 
Shoba Ramachandran
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm not getting the expected results. My output is just "is the description of part-number".
Thanks
Shoba
 
John Wetherbie
Rancher
Posts: 1449
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmm...
Prior to calling the value-of with the concat are you sure that your context node is an order element? If you were in the wrong location that could explain the problem.
 
John Wetherbie
Rancher
Posts: 1449
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, the problem is with the / before item. If you are in an order element node (template-match="order") then the value-of element should look like this:

If you are in the root node (template-match="/") then do this:
 
Shoba Ramachandran
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi JOhn,
No, It is not working.My xsl file is
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:for-each select="/order/customer[@id='216B']">
<xsl:value-of select="concat(item/description, ' is the description of part number ',item/part-number)"/><br></br>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Thanks
Shoba
 
John Wetherbie
Rancher
Posts: 1449
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Remember from the other thread that you can use .. to get to the parent node. I would try placing ../ in from of item and see if that doesn't do the trick.
 
Srikanth Vrudhula
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Shoba,
Your xml file is wrong. If you want the desired output, your xml file should be like this

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="order1.xsl"?>
<order number="312597">
<date>2000/1/1</date>
<!-- this is the customer A-->
<customer id="216A">Company A
<item>
<part-number warehouse="Warehouse 11">E16-25A</part-number>
<description>Production-class widget</description>
<quantity>16</quantity>
</item>
</customer>
<!-- this is the customer B-->
<customer id="216B">Company B
<item>
<part-number warehouse="Warehouse 12">E16-25B</part-number>
<description>Production-class widgetA</description>
<quantity>20</quantity>
</item>
</customer>
</order>
The problem is with your <customer> element. There is no loop in the <customer> element and your calling <xsl:for-each select="/order/customer[@id='216B']">, in your xml file. I have rectified the error. Please check it.
Thnx
Srikanth
divine India Ltd
Mail Id: srikanth.vrudhula@divine.com
 
Rakesh Gudur
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Shobha,
As specified by Srikanth, the <Item> tag should be a child of <Customer> which is not the case with your xml file. The XML file provided by srikanth will clear the error.
reg,
Rakesh.
Software Eng, HYD.
 
Shoba Ramachandran
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, What a silly mistake...
Thanks very much guys for correcting me.
Thanks
Shoba
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic