XSLT插入html内容 [英] XSLT Insert html content

查看:76
本文介绍了XSLT插入html内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在给定的位置插入一些HTML。 XML文件有一个内容节点,里面有实际的HTML。例如,这里是XML的内容部分:

I'm trying to insert some HTML at a given point. The XML file has a content node, which inside that has actual HTML. For exmaple here is the content section of the XML:

-----------------
<content>
    <h2>Header</h2>
    <p><a href="...">some link</a></p>
    <p><a href="...">some link1</a></p>
    <p><a href="...">some link2</a></p>
</content>
-----------------

我需要在标题后面但在第一个链接之前插入一个链接,在它自己的p标签内。

I need to insert a link after the header but before the first link, inside its own p tag. A little rusty with XSLT, any help is appreciated!

推荐答案

给出这个数据源:

<html>
    <head/>
    <body>
        <content>
            <h2>Header</h2>
            <p><a href="...">some link</a></p>
            <p><a href="...">some link1</a></p>
            <p><a href="...">some link2</a></p>
        </content>
    </body>
</html>

此样式表将执行您想要的操作:

This stylesheet will do what you want to do:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>
    <xsl:template match="/html/body/content/h2">
        <xsl:copy>
            <xsl:apply-templates/>
        </xsl:copy>
        <p><a href="...">your new link</a></p>
    </xsl:template>
</xsl:stylesheet>

这篇关于XSLT插入html内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆