给定以下xml:
<items>
<item id="item1">
<description id="desc">
<?RELAPP description="Relative" loc="start"?>
<heading id="h1" level="1">HEADING 1</heading>
<p id="p2" num="1">Paragraph A</p>
<?RELAPP description="Relative" loc="end"?>
<?SUMM description="Summary" loc="start"?>
<heading id="h2" level="1">HEADING 2</heading>
<p id="p3" num="2">Paragraph B</p>
<p id="p4" num="3">Paragraph C</p>
<heading id="h3" level="1">HEADING 3</heading>
<p id="p5" num="4">Paragraph D</p>
<p id="p6" num="5">Paragraph E</p>
<?SUMM description="Summary" loc="end"?>
<?drawings description="Drawings" loc="start"?>
<drawings>
<heading id="h4" level="1">HEADING 4</heading>
<p id="p7" num="6">Paragraph F</p>
<p id="p8" num="7">Paragraph G</p>
</drawings>
<?drawings description="Drawings" loc="end"?>
</description>
</item>
</items>
我正在尝试获取以下文本:
<?SUMM description="Summary" loc="start"?>
和
<?SUMM description="Summary" loc="end"?>
那是:
HEADING 2 Paragraph B Paragraph C HEADING 3 Paragraph D Paragraph E
希望标题和段落之间有一些分离。
我能想到的最好的 xsl 是:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/items">
<myItems>
<xsl:apply-templates/>
</myItems>
</xsl:template>
<xsl:template match="item">
<xsl:element name="info">
<xsl:element name="summaryPI">
<xsl:for-each select="description/processing-instruction('SUMM')">
<xsl:value-of select="."/>
</xsl:for-each>
</xsl:element>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
但它只会让我明白:
<?xml version="1.0" encoding="UTF-8"?>
<myItems>
<info>
<summaryPI>description="Summary" loc="start"description="Summary" loc="end"</summaryPI>
</info>
</myItems>
我应该使用什么规则来获取我想要的文本?我尝试使用前兄弟和后兄弟,但我无法让它工作。我正在使用 1.0 版。