1

Sample 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>

Sample Output:

<p class="author editor2>Test</p>;

I need a sample xslt file to create the above output through xslt.

4

1 回答 1

0

This XSLT will do the trick for you:

<?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>
于 2013-08-31T17:03:56.933 回答