XSLT-如果supertag包含特定术语,如何忽略XML中的子标记
我正在尝试更改XSLT,以便在XML中的超级标记包含特定单词时,不会选择子标记 在本例中,当超级标记XSLT-如果supertag包含特定术语,如何忽略XML中的子标记,xslt,Xslt,我正在尝试更改XSLT,以便在XML中的超级标记包含特定单词时,不会选择子标记 在本例中,当超级标记包含单词“Galaxy”时,我不希望显示子标记 提前谢谢 我的XML <formalpara> Galaxy <para> <bridgehead>Galaxy Zoo</bridgehead> <sliceXML>Galaxy</sliceXML> The human eye is far better at
包含单词“Galaxy”时,我不希望显示子标记
提前谢谢
我的XML
<formalpara>
Galaxy
<para>
<bridgehead>Galaxy Zoo</bridgehead>
<sliceXML>Galaxy</sliceXML>
The human eye is far better at identifying characteristics of galaxies
than any computer. So Galaxy Zoo has called for everyday citizens to
help in a massive identification project. Well over a hundred thousand
people have helped identify newly discovered galaxies. Now you can, too.
</para>
</formalpara>
银河系
银河动物园
银河系
人眼在识别星系特征方面要高得多
比任何计算机都好。所以银河动物园呼吁普通市民
帮助一个大规模的鉴定项目。远远超过十万
人们帮助确认了新发现的星系。现在你也可以了。
我的XSLT
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:sparql-results="http://www.w3.org/2005/sparql-results#" version="1.0">
<xsl:template match="/">
<xsl:call-template name="results"/>
<xsl:message>FROM simpleHMHTransform XSLT8</xsl:message>
</xsl:template>
<xsl:template name="results">
<xsl:for-each select="//formalpara">
<xsl:call-template name="formalpara"/>
</xsl:for-each>
<xsl:for-each select="//para">
<xsl:call-template name="para"/>
</xsl:for-each>
</xsl:template>
<xsl:template name="formalpara">
<div id="formalpara">
<xsl:copy-of select="text()"/>
</div>
</xsl:template>
<xsl:template name="para">
<div id="para">
<xsl:copy-of select="text()"/>
</div>
</xsl:template>
从SimpleHMH转换XSLT8
我的电流输出
<?xml version="1.0" encoding="UTF-8"?><div xmlns:sparql-results="http://www.w3.org/2005/sparql-results#" id="formalpara">
Galaxy
</div><div xmlns:sparql-results="http://www.w3.org/2005/sparql-results#" id="para">
The human eye is far better at identifying characteristics of galaxies
than any computer. So Galaxy Zoo has called for everyday citizens to
help in a massive identification project. Well over a hundred thousand
people have helped identify newly discovered galaxies. Now you can, too.
</div>
银河系
人眼在识别星系特征方面要高得多
比任何计算机都好。所以银河动物园呼吁普通市民
帮助一个大规模的鉴定项目。远远超过十万
人们帮助确认了新发现的星系。现在你也可以了。
我的期望输出
<?xml version="1.0" encoding="UTF-8"?><div xmlns:sparql-results="http://www.w3.org/2005/sparql-results#" id="formalpara">
Galaxy
</div>
银河系
您应该真正执行xsl:apply templates
而不是调用命名模板。然后可以添加此模板:
<xsl:template match="formalpara[contains(text(),'Galaxy')]/para"/>
稍后我可以举一个完整的例子
完整示例: XML输入
<formalpara>
Galaxy
<para>
<bridgehead>Galaxy Zoo</bridgehead>
<sliceXML>Galaxy</sliceXML>
The human eye is far better at identifying characteristics of galaxies
than any computer. So Galaxy Zoo has called for everyday citizens to
help in a massive identification project. Well over a hundred thousand
people have helped identify newly discovered galaxies. Now you can, too.
</para>
</formalpara>
<div xmlns:sparql-results="http://www.w3.org/2005/sparql-results#" id="formalpara">
Galaxy
</div>
银河系
银河动物园
银河系
人眼在识别星系特征方面要高得多
比任何计算机都好。所以银河动物园呼吁普通市民
帮助一个大规模的鉴定项目。远远超过十万
人们帮助确认了新发现的星系。现在你也可以了。
XSLT1.0
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:sparql-results="http://www.w3.org/2005/sparql-results#">
<xsl:output indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="formalpara">
<div id="formalpara">
<xsl:apply-templates/>
</div>
</xsl:template>
<xsl:template match="formalpara[contains(text(),'Galaxy')]/para"/>
<xsl:template match="para">
<div id="para">
<xsl:apply-templates/>
</div>
</xsl:template>
</xsl:stylesheet>
XML输出
<formalpara>
Galaxy
<para>
<bridgehead>Galaxy Zoo</bridgehead>
<sliceXML>Galaxy</sliceXML>
The human eye is far better at identifying characteristics of galaxies
than any computer. So Galaxy Zoo has called for everyday citizens to
help in a massive identification project. Well over a hundred thousand
people have helped identify newly discovered galaxies. Now you can, too.
</para>
</formalpara>
<div xmlns:sparql-results="http://www.w3.org/2005/sparql-results#" id="formalpara">
Galaxy
</div>
银河系
注意:我还将
contains()
更改为contains(text(),'Galaxy')
,因此它只查看formalpara
的直接子项文本。谢谢DevNull,完整的示例将非常好,我会在这一帮助下尝试并找出它。