views:

30

answers:

2

My xml looks like

<details>
  <addr>
      <streetAddressLine>90822 abc lane</streetAddressLine>
      <streetAddressLine>apt b</streetAddressLine>
      <!-- streetAddressLine element is repeatable -->
      <state>xyz</state>
  </addr>
</details>

I am looking for xpath expression which can give me the length of string-length(streetAddressLine[0]) + string-length (streetAddressLine[1]) + ..... + string-length(streetAddressLine[n])

+1  A: 
string-length(string-join(/details/addr/streetAddressLine/text(),""))
Dennis Knochenwefel
+1  A: 

Now that we know you want an XPath 2.0 solution, this expression:

sum(/details/addr/streetAddressLine/string-length())

Result:

19

For a XSLT 1.0 solution, this stylesheet:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
 <xsl:template match="/">
  <xsl:variable name="vStreetAddressLines">
   <xsl:copy-of select="/details/addr/streetAddressLine"/>
  </xsl:variable>
  <xsl:value-of select="string-length($vStreetAddressLines)"/>
 </xsl:template>
</xsl:stylesheet>

Output:

19
Alejandro
Good answer, +1. I think in XPath 2.0 you are required to specify `string-length(.)`, not just `string-length()`
Dimitre Novatchev