【发布时间】:2011-10-01 08:46:06
【问题描述】:
这是 XML 文档。
<w:document xmlns:w="w">
<w:body>
<w:p>
<w:pPr>
<w:pStyle w:val="Normal"/>
</w:pPr>
<w:r>
<w:t>
Para1
</w:t>
</w:r>
</w:p>
<w:p>
<w:pPr>
<w:pStyle w:val="Heading1"/>
</w:pPr>
<w:r>
<w:t>
Para2
</w:t>
</w:r>
</w:p>
<w:p>
<w:pPr>
<w:pStyle w:val="Heading2"/>
</w:pPr>
<w:r>
<w:t>
Para3
</w:t>
</w:r>
</w:p>
<w:p>
<w:pPr>
<w:pStyle w:val="Heading1"/>
</w:pPr>
<w:r>
<w:t>
Para4
</w:t>
</w:r>
</w:p>
<w:p>
<w:pPr>
<w:pStyle w:val="Heading2"/>
</w:pPr>
<w:r>
<w:t>
Para5
</w:t>
</w:r>
</w:p>
<w:tbl>
<w:tr>
<w:tc>
<w:p>
<w:r>
<w:t>
Para6
</w:t>
</w:r>
</w:p>
</w:tc>
<w:tc>
<w:p>
<w:r>
<w:t>
Para7
</w:t>
</w:r>
</w:p>
</w:tc>
</w:tr>
</w:tbl>
<w:p>
<w:pPr>
<w:pStyle w:val="Heading1"/>
</w:pPr>
<w:r>
<w:t>
Para8
</w:t>
</w:r>
</w:p>
<w:tbl>
<w:tr>
<w:tc>
<w:p>
<w:r>
<w:t>
Para9
</w:t>
</w:r>
</w:p>
</w:tc>
<w:tc>
<w:p>
<w:r>
<w:t>
Para10
</w:t>
</w:r>
</w:p>
</w:tc>
</w:tr>
</w:tbl>
<w:p>
<w:pPr>
<w:pStyle w:val="Heading2"/>
</w:pPr>
<w:r>
<w:t>
Para11
</w:t>
</w:r>
</w:p>
</w:body>
</w:document>
现在,
我想先搜索
<w:p><w:pPr><w:pStyle>,它的w:val属性值以“标题”开头。找到这个之后,将该属性值(例如,第二个
<w:p><w:pPr><w:pStyle>中的Heading1)分配给一个变量(例如,xslt文件中的variableName)。将该变量(例如,xslt 文件中的 topLevelHeadings)分配到我想要的另一个变量中。
这是供您参考的 Xslt 文件...
<xsl:template match="*">
<Document>
<xsl:variable name="variableName" select="?"/> <!-- here i want the stuff -->
<xsl:variable name="topLevelHeadings" select = "//w:body/w:p[w:pPr[w:pStyle(@w:val,'$variableName')]]"/>
<xsl:choose>
<xsl:when test="$topLevelHeadings">
<!-- Do things here -->
</xsl:when>
<xsl:otherwise>
<!-- Do things here -->
</xsl:otherwise>
</xsl:choose>
</Document>
</xsl:template>
请指导我摆脱这个问题...
【问题讨论】:
-
您的输入 XML 中甚至没有任何
<w:pPr>元素。 -
@TOmalak:非常抱歉。我现在会更新...非常感谢