示例XML:
<xml version="1.0" encoding="UTF-8" standalone="yes"?>
<w:wordDocument xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml">
<w:styles>
<w:style w:type="paragraph" w:styleId="authoreditor2"><w:name w:val="author editor2" />
</w:style>
</w:styles>
<w:body>
<w:p>
<w:pPr>
<w:pStyle w:val="authoreditor2"/>
</w:pPr>
<w:r>
<w:t>Test</w:t>
</w:r>
</w:p>
</w:body>
</w:wordDocument>
示例输出:
<p class="author editor2>Test</p>;
我需要一个示例xslt文件来通过xslt创建上面的输出。
答案 0 :(得分:0)
这个XSLT可以帮到你:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:my="http://www.example.com" xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl" exclude-result-prefixes="xs xd w my" version="2.0">
<xsl:template match="text()"/>
<xsl:template match="w:p">
<p class="{my:getClass(.)}">
<xsl:value-of select="normalize-space(.)"/>
</p>
</xsl:template>
<xsl:variable name="styles" select="/*/w:styles" />
<xsl:function name="my:getClass">
<xsl:param name="curElem" />
<xsl:variable name="curElemStyleName" select="$curElem//w:pStyle/@w:val"/>
<xsl:variable name="curStyle" select="$styles//*[@w:styleId = $curElemStyleName]"/>
<xsl:sequence select="$curStyle/w:name/@w:val"/>
</xsl:function>
</xsl:stylesheet>