Extracting some data from XML

2020-02-07 10:35发布

<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?

标签: xml xslt
2条回答
我欲成王,谁敢阻挡
2楼-- · 2020-02-07 10:46

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')  
查看更多
Explosion°爆炸
3楼-- · 2020-02-07 10:48

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).

查看更多
登录 后发表回答