【发布时间】:2011-12-02 12:28:26
【问题描述】:
我对 XSLT 还是很陌生。
这是我试图解决几个小时的问题:
我为 xml 文档自动生成了一个目录,到目前为止效果很好。但是,我想用刚刚生成的 toc 代码替换我的源 xml 中的占位符标记。 所以输出应该包含整个文档,用自动生成的 toc xml 替换 placeholder-toc-tag。
这是我尝试过的:
假设我在文档中的任何位置都有我的 placeholderTag,并且想要替换这个/那些。我认为我可以通过 node() 遍历所有节点并检查节点名称是否等于我的占位符标记:
<xsl:template match="node()">
<xsl:choose>
<xsl:when test="divGen">
<!-- apply other template to generate toc-->
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="node()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
但是 if 语句不会像这样匹配。
编辑: 好的,这是源文档(TEI 编码 - 删除了 TEI 命名空间):
<TEI>
<teiHeader>
<fileDesc>
<titleStmt>
<title>Title</title>
</titleStmt>
<publicationStmt>
<p>Publication information</p>
</publicationStmt>
<sourceDesc>
<p>Information about the source</p>
</sourceDesc>
</fileDesc>
</teiHeader>
<text>
<front>
<titlePage>
<byline>title page details</byline>
</titlePage>
</front>
<body>
<divGen type="toc"/>
<div type="part">
<div type="section">
<head>heading1</head>
</div>
<div type="section">
<head>heading2</head>
</div>
</div>
<div type="part">
<div type="section">
<head>heading3</head>
</div>
<div type="section">
<head>heading4</head>
</div>
<div type="section">
<head>heading5</head>
</div>
</div>
</body>
<back> </back>
</text>
我想从头值自动生成目录,并用自动生成的目录代码替换 divGen 标记。但是请注意,divGen 标签可以在文档中的任何位置,但不能在正文之外。
有什么想法吗?
克里斯
【问题讨论】:
-
您能否提供示例输入 XML 和所需的输出?
-
添加了一个示例输入,输出对于我认为的示例并不重要,只是标题应该以任何方式出现
标签: xslt