我只需使用以下形式(无需处理指令)将 XML 文档转换为 WordML 文档(如果可以称其为简单的话!):
<body>
<p>
<r>This is the <italic>standard</italic> text run.</r>
</p>
</body>
根据 WordML 文档,转换后的 XML 应如下所示:
<w:body>
<w:p>
<w:r>
<w:t>This is the </w:t>
</w:r>
</w:p>
<w:p>
<w:pPr>
<w:i/>
</w:pPr>
<w:r>
<w:t>standard</w:t>
</w:r>
</w:p>
<w:p>
<w:r>
<w:t> text run.</w:t>
</w:r>
</w:p>
</w:body>
我应该如何创建 XSLT 转换以正确处理斜体标签??..
最佳答案
这种转变:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:w="some:w" exclude-result-prefixes="w">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="body">
<w:body>
<xsl:apply-templates/>
</w:body>
</xsl:template>
<xsl:template match="p/r/text()">
<w:p>
<w:r>
<w:t><xsl:value-of select="."/></w:t>
</w:r>
</w:p>
</xsl:template>
<xsl:template match="p/r/italic/text()">
<w:p>
<w:pPr>
<w:i/>
</w:pPr>
<w:r>
<w:t><xsl:value-of select="."/></w:t>
</w:r>
</w:p>
</xsl:template>
<xsl:template match="text()"/>
</xsl:stylesheet>
应用于提供的 XML 文档时:
<body>
<p>
<r>This is the <italic>standard</italic> text run.</r>
</p>
</body>
产生想要的正确结果:
<w:body xmlns:w="some:w">
<w:p>
<w:r>
<w:t>This is the </w:t>
</w:r>
</w:p>
<w:p>
<w:pPr>
<w:i/>
</w:pPr>
<w:r>
<w:t>standard</w:t>
</w:r>
</w:p>
<w:p>
<w:r>
<w:t> text run.</w:t>
</w:r>
</w:p>
</w:body>
关于xml - 将斜体 XML 标签转换为 WordML 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12469071/