我想在<和>之间选择String。
投入:
<p type="Endnote Text"><p:endnote_bl1>This is a bullet list in an endnote</p>
<p type="Endnote Text"><p:endnote_bl2>This is a bullet list in an endnote</p>
<p type="Endnote Text"><p:endnote_bl3>This is a bullet list in an endnote</p>我想从文本中选择p:endnote_bl1,p:endnote_bl2, etc..。它意味着<和>之间的任何文本。我如何才能为此编写XPath。
发布于 2019-07-29 12:13:38
在XSLT中,使用xpath,您可以简单地选择所有p元素(或者tps:p元素,如果您有名称空间),并使用substring-before和substring-after提取文本,不过请注意,这假设每个<和>都有一个匹配项。
<xsl:for-each select="//p[@type='Endnote Text']">
<xsl:value-of select="substring-before(substring-after(., '<'), '>')" />
<xsl:text> </xsl:text>
</xsl:for-each>在http://xsltfiddle.liberty-development.net/bnnZX7上看到它的动作
如果您可以使用XSLT2.0,您可以不使用xsl:for-each.
<xsl:value-of select="//p[@type='Endnote Text']/substring-before(substring-after(., '<'), '>')" separator=" " />或者也可以在XSLT2.0中使用replace .
<xsl:value-of select="//p[@type='Endnote Text']/replace(., '<(.+)>.*', '$1')" separator=" " />发布于 2019-07-29 12:20:47
您可以只使用xpath,如果我们这样修复您的xml:
<doc>
<p type="Endnote Text"><p:endnote_bl1>This is a bullet list in an endnote</p>
<p type="Endnote Text"><p:endnote_bl2>This is a bullet list in an endnote</p>
<p type="Endnote Text"><p:endnote_bl3>This is a bullet list in an endnote</p>
</doc>然后这个表情,
doc/p/substring(./text(),2,13)将选择
p:endnote_bl1
p:endnote_bl2
p:endnote_bl3https://stackoverflow.com/questions/57252502
复制相似问题