这是我的Xml文件..。
<w:document>
<w:body>
<w:p>
<w:r>
<w:t>
Paragraph1
</w:t>
</w:r>
</w:p>
</w:body>
</w:document>这是我的第二个XML文件.
<w:document>
<w:body>
<w:p>
<w:r>
<w:pict>
<v:shape>
<v:textbox>
<w:txbxContent>
<w:p>
<w:r>
<w:t>
Paragraph2
</w:t>
</w:r>
</w:p>
</w:txbxContent>
<v:textbox>
</v:shape>
</w:pict>
</w:r>
</w:p>
</w:body>
</w:document>在这里,每当我找到//w:body/w:p/w:r/w:t时,我就编写了一个xslt文件并调用了我的模板。
for example,
<xsl:apply-templates select="//w:body/w:p[w:r[w:t]]">
</xsl:apply-templates>我自己的模板是
<xsl:template match="w:p">
Do something here
</xsl:template>我的xslt在我的第一个xml document.But中正确地工作--它不能处理第二个that.So和一些类似that.So的场景,如何通过在这里修改这个查询来实现这两个场景.
<xsl:apply-templates select="?????"> <!-- how to find the case that also matching my second xml file -->
</xsl:apply-templates>请引导我离开这个问题..。
发布于 2011-09-21 12:10:20
使用
<xsl:apply-templates select="//w:p[w:r/w:t]"> 您可以将模板的match属性更改为稍微具体一点:
<xsl:template match="w:p[w:r/w:t]">
<!-- Processing here -->
</xsl:template> 完整代码
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:w="w:w">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<xsl:apply-templates select="//w:p[w:r/w:t]"/>
</xsl:template>
<xsl:template match="w:p[w:r/w:t]">
<xsl:value-of select="w:r/w:t"/>
</xsl:template>
</xsl:stylesheet>将此转换应用于第一个提供的XML文档(为使其格式良好而定义的命名空间):
<w:document xmlns:w="w:w">
<w:body>
<w:p>
<w:r>
<w:t>
Paragraph1
</w:t>
</w:r>
</w:p>
</w:body>
</w:document>正确的结果是
Paragraph1当对第二个提供的"XML"应用相同的转换时(它的格式严重错误,我花了许多分钟才使其格式良好!):
<w:document xmlns:w="w:w">
<w:body>
<w:p>
<w:r>
<w:pict>
<v:shape xmlns:v="v:v">
<v:textbox>
<w:txbxContent>
<w:p>
<w:r>
<w:t>
Paragraph2
</w:t>
</w:r>
</w:p>
</w:txbxContent>
</v:textbox>
</v:shape>
</w:pict>
</w:r>
</w:p>
</w:body>
</w:document>再次想要的结果是生成
Paragraph2https://stackoverflow.com/questions/7499379
复制相似问题