我對XSLT很陌生。XSLT用生成的標籤替換標籤
這是我想現在要解決好幾個小時的問題:
我自動生成的內容表的XML文檔偉大的工程至今。不過,我想用剛剛生成的toc代碼替換源xml中的佔位符標記。 因此,輸出應該包含帶有自動生成的toc xml替換的佔位符toc標籤的整個文檔。
這是我已經試過:
比方說,我有我的placeholderTag任何地方的文件中,並要替換該/那些。我以爲我可以通過節點通過所有節點環路()和檢查節點名稱等於我的佔位符標記:
<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>
我想自動生成從頭部值的TOC和更換divGen標籤由自動生成的toc代碼。但請注意,divGen標籤可以位於文檔中的任何位置,但不在身體之外。
任何想法?
克里斯
您能否提供樣本輸入XML和期望的輸出? –
增加了一個樣本輸入,輸出是不是因爲我覺得樣品重要,只是標題應該出現在任何方式 – Chris