看来我正在努力实现无法实现的目标,但它是: 我有一个 XML 结构,如:
<?xml version="1.0" encoding="UTF-8"?>
<article>
<h1><p mystyle="texte"><b>Barème</b> sur 20 points</p></h1>
</article>
如果我调用 value-of 和 disable-output-escaping="yes",我会得到一个格式很好的结构:
<?xml version="1.0" encoding="UTF-8"?>
<article>
<h1>
<p mystyle="texte"><b>Barème</b> sur 20 points</p>
</h1>
</article>
问题是我只想得到 p 标签的孩子:
<?xml version="1.0" encoding="UTF-8"?>
<article>
<h1>
<b>Barème</b> sur 20 points
</h1>
</article>
我接触孩子的任何尝试都失败了。
- 将未转义的字符串设置为变量并处理该变量
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="1.0" >
<xsl:template match="/">
<xsl:apply-templates select="*"></xsl:apply-templates>
</xsl:template>
<xsl:template match="h1">
<xsl:variable name="unescaped">
<xsl:value-of select="." disable-output-escaping="yes"/>
</xsl:variable>
<xsl:value-of select="$unescaped/*"/>
</xsl:template>
</xsl:stylesheet>
- 尝试将 xpath 设置为 ./*(空结果)
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="1.0" >
<xsl:template match="/">
<xsl:apply-templates select="*"></xsl:apply-templates>
</xsl:template>
<xsl:template match="h1">
<xsl:value-of select="./*" disable-output-escaping="yes"/>
</xsl:template>
</xsl:stylesheet>
我一直在读到禁用输出转义的限制之一是无法处理“节点”。 是这样吗?
提前感谢您的任何提示。