添加页眉和页脚在XSLT文件

问题描述 投票:0回答:1

我有把XML到Word文档的XSLT文件。我的问题是我要添加页眉和页脚在文档中。我该怎么做?

我的问题是基本与此类似Header and footer and page numbers using xslt

有关页眉和页脚的更多帮助,可以发现here。基本上,我需要使用这些标签,但我怎么使用它在我的模板?难道我把它到底还是中间的某个位置?我也想改变这个词的页面布局到景观是肖像是默认的。

<fo:region-before> defines the top region (header)
<fo:region-after> defines the bottom region (footer)

假设这是我的XSLT

<?xml version="1.0" encoding="ISO-8859-1"?>

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
  <html>
  <body>
    <h2>My CD Collection</h2>
    <table border="1">
      <tr bgcolor="#9acd32">
        <th>Title</th>
        <th>Artist</th>
      </tr>
      <xsl:for-each select="catalog/cd">
        <tr>
          <td><xsl:value-of select="title"/></td>
          <td><xsl:value-of select="artist"/></td>
        </tr>
      </xsl:for-each>
    </table>
  </body>
  </html>
</xsl:template>

</xsl:stylesheet>

上面的例子中已经从w3school复制

xml xslt ms-word xsl-fo
1个回答
1
投票

正如很多评论说,不生成HTML,但无论哪种XSL-FO或Word XML完全。由于字XML是最直接的方法,我会帮你用最小的样品,我能想到的是返回一个类似的HTML的东西,但页眉和页脚。其实,我只是在Word中打开一个生成的HTML,保存的如Word XML,添加页眉和页脚,并摆脱了大部分superflues XML标记Word会自动添加的。

把你的根XSL模板中之后,添加的每个桌子周围行,并动态填充页眉/页脚你喜欢的方式..

<w:wordDocument xmlns:aml="http://schemas.microsoft.com/aml/2001/core" xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml" xmlns:wx="http://schemas.microsoft.com/office/word/2003/auxHint" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" xmlns:wsp="http://schemas.microsoft.com/office/word/2003/wordml/sp2" xmlns:sl="http://schemas.microsoft.com/schemaLibrary/2003/core" w:macrosPresent="no" w:embeddedObjPresent="no" w:ocxPresent="no" xml:space="preserve">

<w:docPr>
<w:view w:val="print"/>
<w:zoom w:percent="100"/>
</w:docPr>

<w:styles>
<w:style w:type="paragraph" w:styleId="Heading2">
<w:name w:val="heading 2"/>
<wx:uiName wx:val="Heading 2"/>
<w:basedOn w:val="Standaard"/>
<w:pPr>
<w:spacing w:before="100" w:before-autospacing="on" w:after="100" w:after-autospacing="on"/>
<w:outlineLvl w:val="1"/>
</w:pPr>
<w:rPr>
<w:b/>
<w:sz w:val="36"/>
</w:rPr>
</w:style>

<w:style w:type="paragraph" w:styleId="Headertext">
<w:name w:val="header"/>
<wx:uiName wx:val="Header text"/>
<w:basedOn w:val="Standaard"/>
<w:pPr>
<w:tabs>
<w:tab w:val="center" w:pos="4536"/>
<w:tab w:val="right" w:pos="9072"/>
</w:tabs>
</w:pPr>
</w:style>

<w:style w:type="paragraph" w:styleId="Footertext">
<w:name w:val="footer"/>
<wx:uiName wx:val="Footer text"/>
<w:basedOn w:val="Standaard"/>
<w:pPr>
<w:tabs>
<w:tab w:val="center" w:pos="4536"/>
<w:tab w:val="right" w:pos="9072"/>
</w:tabs>
</w:pPr>
</w:style>
</w:styles>

<w:body>
<w:p>
<w:pPr>
<w:pStyle w:val="Heading2"/>
</w:pPr>
<w:r>
<w:t>My CD Collection</w:t>
</w:r>
</w:p>

<w:tbl>
<w:tblPr>
<w:tblW w:w="5000" w:type="pct"/>
<w:tblCellSpacing w:w="15" w:type="dxa"/>
<w:tblBorders>
<w:top w:val="outset" w:sz="6" wx:bdrwidth="15" w:space="0" w:color="auto"/>
<w:left w:val="outset" w:sz="6" wx:bdrwidth="15" w:space="0" w:color="auto"/>
<w:bottom w:val="outset" w:sz="6" wx:bdrwidth="15" w:space="0" w:color="auto"/>
<w:right w:val="outset" w:sz="6" wx:bdrwidth="15" w:space="0" w:color="auto"/>
</w:tblBorders>
<w:tblCellMar>
<w:top w:w="15" w:type="dxa"/>
<w:left w:w="15" w:type="dxa"/>
<w:bottom w:w="15" w:type="dxa"/>
<w:right w:w="15" w:type="dxa"/>
</w:tblCellMar>
<w:tblLook w:val="04A0"/>
</w:tblPr>
<w:tr>
<w:tc>
<w:p>
<w:r>
<w:rPr>
<w:b/>
</w:rPr>
<w:t>Title</w:t>
</w:r>
</w:p>
</w:tc>
<w:tc>
<w:p>
<w:r>
<w:rPr>
<w:b/>
</w:rPr>
<w:t>Artist</w:t>
</w:r>
</w:p>
</w:tc>
</w:tr>
<w:tr>
<w:tc>
<w:p>
<w:r>
<w:t>title1</w:t>
</w:r>
</w:p>
</w:tc>
<w:tc>
<w:p>
<w:r>
<w:t>artist1</w:t>
</w:r>
</w:p>
</w:tc>
</w:tr>
<w:tr>
<w:tc>
<w:p>
<w:r>
<w:t>title2</w:t>
</w:r>
</w:p>
</w:tc>
<w:tc>
<w:p>
<w:r>
<w:t>artist2</w:t>
</w:r>
</w:p>
</w:tc>
</w:tr>
</w:tbl>

<w:p />

<w:hdr w:type="odd">
<w:p>
<w:pPr>
<w:pStyle w:val="Headertext"/>
</w:pPr>
<w:r>
<w:t>Header text</w:t>
</w:r>
<w:r>
<w:tab/>
<w:t>center</w:t>
</w:r>
<w:r>
<w:tab/>
<w:t>right</w:t>
</w:r>
</w:p>
</w:hdr>

<w:ftr w:type="odd">
<w:p>
<w:pPr>
<w:pStyle w:val="Footertext"/>
</w:pPr>
<w:r>
<w:t>left</w:t>
</w:r>
<w:r>
<w:tab/>
<w:t>Footer text</w:t>
</w:r>
<w:r>
<w:tab/>
</w:r>
<w:r>
<w:fldChar w:fldCharType="begin"/>
</w:r>
<w:r>
<w:instrText>PAGE   \* MERGEFORMAT</w:instrText>
</w:r>
<w:r>
<w:fldChar w:fldCharType="separate"/>
</w:r>
<w:r>
<w:t>1</w:t>
</w:r>
<w:r>
<w:fldChar w:fldCharType="end"/>
</w:r>
</w:p>
</w:ftr>
</w:body>
</w:wordDocument>

它还有助于确保下列处理指令获取根元素之前添加:

<?mso-application progid="Word.Document"?>

HTH!

© www.soinside.com 2019 - 2024. All rights reserved.