Connecting Tech Pros Worldwide Forums | Help | Site Map

Concatinating 2 tags inside the same node with xslt XSLT

Newbie
 
Join Date: Oct 2009
Posts: 1
#1: 4 Weeks Ago
Hi All,

I just started working with XSLT, so this question might be obvios for some; i'm struggling trying to concatenate 2 tags inside the same node. I will be receiving one XML file and my output is another XML file.

This is a sample of the xml i will be receiving:
Expand|Select|Wrap|Line Numbers
  1. <EquipmentList>
  2.     <EquipmentDetail>
  3.     <AssetSupplierName>Dealer 1</AssetSupplierName>
  4.     <Quantity>1</Quantity>
  5.                 <Specification>Asset 1</Specification>
  6.     </EquipmentDetail>
  7.     <EquipmentDetail>
  8.     <AssetSupplierName>Dealer 2</AssetSupplierName>
  9.     <Quantity>1</Quantity>
  10.                  <Specification>Asset 2</Specification>
  11.     </EquipmentDetail>
  12.     <EquipmentDetail>
  13.     <AssetSupplierName>Dealer 3</AssetSupplierName>
  14.     <Quantity>1</Quantity>
  15.                 <Specification>Asset 3</Specification>
  16.     </EquipmentDetail>
  17. <EquipmentList>
This is the code i have:
Expand|Select|Wrap|Line Numbers
  1. <xsl:template match="//Specification">
  2.     <xsl:copy>
  3.         <xsl:copy-of select="concat(., ' ', //EquipmentDetail/AssetSupplierName)"/>
  4.     </xsl:copy>
  5. </xsl:template>
The problem im having is that it always concatenates to Specification to the same AssetSupplierName Tag, i always get

Asset 1 Dealer 1
Asset 2 Dealer 1
Asset 3 Dealer 1

when im really expecting

Asset 1 Dealer 1
Asset 2 Dealer 2
Asset 3 Dealer 3

I have tried putting the same code above inside a for-each and i get the same results...

Thanks in advance!



Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,648
#2: 4 Weeks Ago

re: Concatinating 2 tags inside the same node with xslt XSLT


you have to move (via XPath) from the current node, not from the root node (i.e. //*).
Expand|Select|Wrap|Line Numbers
  1. ../preceding-sibling::AssetSupplierName[1]
(something like that)
Reply