我正在使用这个xml
<body>
<p>The results are used to optimize the design in the next product cycle through the V.</p>
<p> This feedback is represented by arrows between the left and right side of the V<xref ref-type="fig" rid="F1">Figure 1</xref>Physical test benches are often comprised of customized static.</p>
</body>
这是xslt
<xsl:for-each select="body/">
<xsl:value-of select="text()">
</xsl:for-each>
它正在输出
结果用于在下一个产品周期中通过V优化设计。此反馈由V的左侧和右侧之间的箭头表示。
在xref标签之后没有读取字符串。但我想解析它并希望将以下内容作为输出。
结果用于在下一个产品周期中通过V.优化设计。此反馈由V的左侧和右侧之间的箭头表示。物理测试台通常由定制的静态组成。
我应该对Xslt进行哪些更改,以便它也可以传递此标记?
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes" omit-xml-declaration="yes" doctype-public="-//W3C//DTD HTML 4.0 Transitional//EN"/>
<xsl:template match="book-part">
<html>
<head></head>
<body>
<xsl:for-each select="book-meta">
<p>
<b>
<xsl:value-of select="book-title-group/book-title"/>
</b>
</p>
</xsl:for-each>
<xsl:for-each select="book-part-meta">
<p>
<b>
<xsl:value-of select="title-group/title"/>
</b>
</p>
</xsl:for-each>
<xsl:for-each select="body/sec/p">
<xsl:value-of select="text()"/>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
这是我的xml。
<?xml version="1.0" encoding="utf-8"?>
<book-part book-part-type="chapter" book-part-number="1" id="PT-161_ch_1">
<book-meta>
<book-title-group>
<book-title>Software-Hardware Integration in Automotive Product Development</book-title>
</book-title-group>
</book-meta>
<body>
<sec id="ch1.1">
<title>INTRODUCTION</title>
<p>The trends of increased functionality, improved performance, reduced size and increased complexity continue to evolve in the automotive electronics market. New system architectures are providing the performance and memory capability necessary to keep up with the hardware performance and software growth required by the automotive market trends. All of this technology growth implies a higher product cost and increased engineering effort required to develop these new products.</p>
<p>IVV is that portion of the complete product or system life-cycle phase captured in the right-hand side (RHS) of the V-diagram model (see <xref ref-type="fig" rid="F96">Fig. 1</xref>). This RHS portion is sometimes called the “build, test, and deliver phase [<xref ref-type="bibr" rid="R65">1</xref>].” The model’s left-hand side is where the architectural design is functionally partitioned and decomposed into manageable subsystems and components. At the lowest levels of decomposition-i.e., the bottom of the “V”-the resulting subsystems are ready to be recomposed into an integrated whole. This integration phase is where verification, validation, and test of all the hardware and software occur.</p>
</sec>
</body>
</book-part>
答案 0 :(得分:0)
编写另一个模板以捕获xref
元素的内容:
<xsl:template match="xref">
<xsl:value-of select="."/>
</xsl:template>
说完这个,这取决于你不显示的样式表的各个方面。这是一个完整的样式表,也在xref
:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/body">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="p|xref">
<xsl:value-of select="."/>
</xsl:template>
</xsl:stylesheet>
您应该尽可能避免使用xsl:for-each
。使用多个模板和apply-templates
是XSLT更精神的方式。
编辑:我添加了一个与您更新的输入一起使用的样式表,与您尝试过的XSLT解决方案类似。
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes" omit-xml-declaration="yes" doctype-public="-//W3C//DTD HTML 4.0 Transitional//EN"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/book-part">
<html>
<head></head>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="book-meta">
<p>
<b>
<xsl:value-of select="book-title-group/book-title"/>
</b>
</p>
</xsl:template>
<xsl:template match="body|sec|p">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="text()[parent::p]">
<xsl:value-of select="."/>
</xsl:template>
<xsl:template match="text()[parent::xref]"/>
</xsl:stylesheet>
应用于以下输入:
<?xml version="1.0" encoding="utf-8"?>
<book-part book-part-type="chapter" book-part-number="1" id="PT-161_ch_1">
<book-meta>
<book-title-group>
<book-title>Software and Hardware Integration in Automotive Product Development</book-title>
</book-title-group>
</book-meta>
<body>
<sec id="ch1.1">
<title>INTRODUCTION</title>
<p>The trends of increased functionality, improved performance, reduced size and increased complexity continue to evolve in the automotive electronics market.</p>
<p> First part of the sentence <xref ref-type="fig" rid="F96">Fig. 1</xref>second part of the sentence.</p>
</sec>
</body>
</book-part>
您将获得以下输出:
<!DOCTYPE html
PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<p><b>Software and Hardware Integration in Automotive Product Development</b></p>INTRODUCTIONThe trends of increased functionality, improved performance, reduced size and increased complexity continue to evolve in the
automotive electronics market. First part of the sentence second part of the sentence.
</body>
</html>