MrC
MrC

Reputation: 217

Schematron xpath xsl select multiple grandchildren

I have the following XML file structure

<Instance>
  <Reference>
    <RefId>123</RefId>
    <RefName>Company1</RefName>
  </Reference>
  <Reference>
     <RefId>234</RefId>
     <RefName>Company2</RefName>
  </Reference>
  <Reference>
     <RefId>345</RefId>
     <RefName>Company3</RefName>
 </Reference>
</Instance>

I am trying to create a string using xslt or xpath containing the value from the RefId and the RefName elements - ideally something like 'RefId 123, RefName Company1, RefId 234, RefName Company2, RefId 345, RefName Company3' (although I'm not fussy about the separator used.

Upvotes: 0

Views: 63

Answers (1)

hek2mgl
hek2mgl

Reputation: 158040

You can use xslt and the following stylesheet:

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

<xsl:template match="//Instance">
  <xsl:for-each select="Reference">RefId <xsl:value-of select="RefId"/>,RefName<xsl:value-of select="RefName"/>,</xsl:for-each>
</xsl:template>
</xsl:stylesheet> 

Upvotes: 2

Related Questions