Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml 在XSLT文件中添加页眉和页脚_Xml_Xslt_Ms Word_Xsl Fo - Fatal编程技术网

Xml 在XSLT文件中添加页眉和页脚

Xml 在XSLT文件中添加页眉和页脚,xml,xslt,ms-word,xsl-fo,Xml,Xslt,Ms Word,Xsl Fo,我有一个XSLT文件,可以将XML转换为word文档。我的问题是我想在文档中添加页眉和页脚。我该怎么做 我的问题基本上与此相似 可以找到更多关于页眉和页脚的帮助。基本上我需要使用这些标签,但如何在我的模板中使用它?我把它放在结尾还是中间的某个地方?我还想将单词页面布局更改为横向,这是默认设置 <fo:region-before> defines the top region (header) <fo:region-after> defines the bottom reg

我有一个XSLT文件,可以将XML转换为word文档。我的问题是我想在文档中添加页眉和页脚。我该怎么做

我的问题基本上与此相似

可以找到更多关于页眉和页脚的帮助。基本上我需要使用这些标签,但如何在我的模板中使用它?我把它放在结尾还是中间的某个地方?我还想将单词页面布局更改为横向,这是默认设置

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


我的CD收藏
标题
艺术家

上面的示例是从

复制的,正如在大量评论中所说的,不生成HTML,而是完全生成XSL-FO或Word XML。由于Word XML是最直接的方法,我将用我能想到的最小的示例来帮助您,该示例返回类似于HTML的内容,但带有页眉和页脚。事实上,我刚刚在Word中打开了一个生成的HTML,将其保存为Word XML,添加了页眉和页脚,并去掉了Word自动添加的大部分多余的XML标记

将以下内容放在根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>

我的CD收藏
标题
艺术家
标题1
艺人1
标题2
艺人2
标题文本
居中
正确的
左边
页脚文本
页面\*合并格式
1.
它还有助于确保在根元素之前添加以下处理指令:

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


你能把你的问题讲得更清楚一点吗?可能提供您的输入文档、您当前的转换、预期结果。也可以是碎片。其他方面很难理解我已经包括了一个XSLT示例。我在提取数据方面没有问题。我唯一的问题是输入页眉和页脚。等一下。。。有些东西不合逻辑。为什么在HTML中需要xsl fo页眉/页脚?你必须把你的问题框起来,使之接近你真正正在努力解决的问题。Word与
xsl:fo
有什么关系?@Thecrocodilehunter注意到Word能够打开HTML,但据我所知,它不支持页眉和页脚。替代方案可以是完全生成xsl fo,并使用能够生成RTF之类内容的fo处理器。或者用一种XML语法生成一个合适的Word文档,例如Word 2003 XML。生成HTML的另一种方法是生成一个“平面”OPC文件(通过XSLT),哪个Word 2007/2010可以读/写。@jason Flat OPC比Word 2003 XML更复杂。Flat OPC是一种现代格式,可以很容易地与基于标准的WordML(即ECMA 376)进行转换。Word2003XML现在已经有10年的历史了,尽管该模式是可用的,但我认为它没有一个公共规范。