Concatenate multiple node values in xpath

前端 未结 6 1689
旧巷少年郎
旧巷少年郎 2020-12-01 07:32

I have a XML that looks like this


    
            
            Hello
              


        
相关标签:
6条回答
  • 2020-12-01 07:51

    If you need to join xpath-selected text nodes but can not use string-join (when you are stuck with XSL 1.0) this might help:

    <xsl:variable name="x">
        <xsl:apply-templates select="..." mode="string-join-mode"/>
    </xsl:variable>
    joined and normalized: <xsl:value-of select="normalize-space($x)"/>
    
    <xsl:template match="*" mode="string-join-mode">
        <xsl:apply-templates mode="string-join-mode"/>
    </xsl:template>    
    
    <xsl:template match="text()" mode="string-join-mode">
        <xsl:value-of select="."/>
    </xsl:template>    
    
    0 讨论(0)
  • 2020-12-01 07:53

    I used concat method and works well.

    concat(//SomeElement/text(),'_',//OtherElement/text())
    
    0 讨论(0)
  • 2020-12-01 07:58

    Here comes a solution with XSLT:

    <?xml version="1.0" encoding="utf-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="//element3">
        <xsl:value-of select="element4/text()" />.<xsl:value-of select="element5/text()" />
    </xsl:template>
    </xsl:stylesheet>
    
    0 讨论(0)
  • 2020-12-01 08:00

    Try this expression...

    string-join(//element3/(concat(element4/text(), '.', element5/text())), "&#10;")
    
    0 讨论(0)
  • 2020-12-01 08:14

    for $d in $doc/element2/element3 return fn:string-join(fn:data($d/element()), ".").
    $doc stores the Xml.

    0 讨论(0)
  • 2020-12-01 08:17
    <xsl:template match="element3">
            <xsl:value-of select="element4,element5" separator="."/>
        </xsl:template>
    
    0 讨论(0)
提交回复
热议问题