【发布时间】:2021-10-29 08:49:44
【问题描述】:
使用 XSLT 创建 XHTML 文档后,我需要添加一个元素 (link:schemaRef)。
原因是我正在合并 2 个 XHTML 文档,并且只有合并的文档应该包含我需要添加的元素。我缩短了链接的长度只是为了更好地适应示例。
我看不到结果文件有添加的链接。 我的代码明显有问题?
我的代码库:
<!-- Identity transform -->
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<!-- Find and add element in document -->
<xsl:template match="/xhtml:html/xhtml:body/xhtml:div[1]/ix:header/ix:hidden/ix:references">
<xsl:copy>
<xsl:copy-of select="@*" />
<xsl:element name="link:schemaRef">
<xsl:attribute name="xlink:type">simple</xsl:attribute>
<xsl:attribute name="xlink:href">http://example.org</xsl:attribute>
</xsl:element>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
【问题讨论】:
-
您还需要显示两个最小输入样本,以及您获得的输出和您想要的输出。
-
我想你还需要解释一下“文档生成后”是什么意思,你是否以及如何运行两个转换。
-
感谢您的回答,我会更新问题但无法立即完成。