Select 使用 XSLT 按属性划分的唯一元素
Select unique element by attribute using XSLT
我的 XML 有一些奇怪的结构。它是从驱动网站的 CMS 生成的,但我们需要使用数据库的 XML 输出在 Adobe InDesign 中创建打印文档。
我需要 select 一些包含在具有特定 类 的 span 标签中的内容,但我的 XSLT 不工作。
这是原始的 XML 输出:
<newsItem>
<!DOCTYPE xsl:stylesheet[
<!ENTITY bull "•">
]>
<inlineXml>
<h2>Appointments</h2>
<p><span class="PB-biz red bullet">•</span> <span><strong>John Smith</strong></span> interim president and CEO was named to the permanent position.</p>
<p><span class="PB-biz red bullet">•</span> Hospital announced that <span><strong>James Williams</strong></span> will become division president .</p>
</inlineXml>
</newsItem>
这是 XSLT:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform version="1.0">
<xsl:output method="xml" indent="no"/>
<xsl:strip-space elements="*"/>
<xsl:template match="newsItem"> <newsItem><xsl:apply-templates/></newsItem></xsl:template>
<xsl:template match="p">
<p><xsl:apply-templates/></p>
</xsl:template>
<xsl:template match="span[@class='PB-biz']">
<bull><xsl:apply-templates/></bull>">
</xsl:template>
<xsl:template match="span/strong"><xsl:text> </xsl:text><biz-name><xsl:value-of select="normalize-space(.)"/></biz-name><xsl:text> </xsl:text></xsl:template>
</xsl:stylesheet>
这是所需的输出:
<newsItem>
<inlineXml>
<h2>Appointments</h2>
<p><bull>•</bull> <biz-name>John Smith</biz-name> interim president and CEO was named to the permanent position.</p>
<p><bull>•</bull> Hospital announced that <biz-name>James Williams</biz-name> will become division president.</p>
</inlineXml>
</newsItem>
我无法让 selection 为 bullet 实体元素工作。
谢谢
您在 XML 中的 class 是 'PB-biz red bullet'。您匹配 class 'PB-biz'。由于它们不相同,因此匹配 none。更改 XSLT 以匹配 class.
的确切属性值
我的 XML 有一些奇怪的结构。它是从驱动网站的 CMS 生成的,但我们需要使用数据库的 XML 输出在 Adobe InDesign 中创建打印文档。
我需要 select 一些包含在具有特定 类 的 span 标签中的内容,但我的 XSLT 不工作。
这是原始的 XML 输出:
<newsItem>
<!DOCTYPE xsl:stylesheet[
<!ENTITY bull "•">
]>
<inlineXml>
<h2>Appointments</h2>
<p><span class="PB-biz red bullet">•</span> <span><strong>John Smith</strong></span> interim president and CEO was named to the permanent position.</p>
<p><span class="PB-biz red bullet">•</span> Hospital announced that <span><strong>James Williams</strong></span> will become division president .</p>
</inlineXml>
</newsItem>
这是 XSLT:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform version="1.0">
<xsl:output method="xml" indent="no"/>
<xsl:strip-space elements="*"/>
<xsl:template match="newsItem"> <newsItem><xsl:apply-templates/></newsItem></xsl:template>
<xsl:template match="p">
<p><xsl:apply-templates/></p>
</xsl:template>
<xsl:template match="span[@class='PB-biz']">
<bull><xsl:apply-templates/></bull>">
</xsl:template>
<xsl:template match="span/strong"><xsl:text> </xsl:text><biz-name><xsl:value-of select="normalize-space(.)"/></biz-name><xsl:text> </xsl:text></xsl:template>
</xsl:stylesheet>
这是所需的输出:
<newsItem>
<inlineXml>
<h2>Appointments</h2>
<p><bull>•</bull> <biz-name>John Smith</biz-name> interim president and CEO was named to the permanent position.</p>
<p><bull>•</bull> Hospital announced that <biz-name>James Williams</biz-name> will become division president.</p>
</inlineXml>
</newsItem>
我无法让 selection 为 bullet 实体元素工作。
谢谢
您在 XML 中的 class 是 'PB-biz red bullet'。您匹配 class 'PB-biz'。由于它们不相同,因此匹配 none。更改 XSLT 以匹配 class.
的确切属性值