praveen
praveen

Reputation: 63

Extracting some data from XML

<block1>
  <tag>
    <name>59</name>
    <value>/00940001812410930828 FONDITEL VALORES AV SAU ATAM PEDRO TEIXERIA 8 PLANTA 7A 28020MADRID
    </value>
  </tag>
</block1>

I need the output as 00940001812410930828 ,FONDITEL VALORES AV SAU ATAM PEDRO TEIXERIA 8 PLANTA 7A 28020MADRID

Can any one help me please?

Upvotes: 0

Views: 133

Answers (2)

user357812
user357812

Reputation:

This XPath expression:

concat(
   substring-after(
      substring-before(
         /block1/tag/value,
         ' '
      ),
      '/'
   ),
   ' ,',
   substring-after(
      /block1/tag/value,
      ' '
   )
)

Or this XSLT stylesheet:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="value">
        <xsl:value-of select="substring-after(
                                 substring-before(
                                    /block1/tag/value,
                                    ' '
                                 ),
                                 '/'
                              )"/>
        <xsl:text> ,</xsl:text>
        <xsl:value-of select="substring-after(
                                 /block1/tag/value,
                                 ' '
                              )"/>
    </xsl:template>
</xsl:stylesheet>

And a simple XPath 2.0 expression:

replace(/block1/tag/value,'/([^ ]* )(.*)','$1,$2')  

Upvotes: 1

Alex Nikolaenkov
Alex Nikolaenkov

Reputation: 2545

If I'm not missing anything try the following approach:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="//value">
        <xsl:value-of select="substring-after('/', normalize-space(.))"/>
    </xsl:template>
</xsl:stylesheet>

In case you want to concentrate on string processing you should probably consider improving your xml markup instead of that. Otherwise working with string values with xslt 1.0 is tedious. (if you're using 2.0 then there is a list of predefined functions exactly for this purpose (like fn:tokenize).

Upvotes: 1

Related Questions