Xml 如果在xslt文件中
我需要帮助来编写xslt文件的条件 我有这样的想法:Xml 如果在xslt文件中,xml,xslt,Xml,Xslt,我需要帮助来编写xslt文件的条件 我有这样的想法: <some_tag style="blank">ten</some_tag> <some_tag style="p">some text here </some_tag> <some_tag style="p">some other text here </some_tag> <some_tag style="blank">two</some_tag
<some_tag style="blank">ten</some_tag>
<some_tag style="p">some text here </some_tag>
<some_tag style="p">some other text here </some_tag>
<some_tag style="blank">two</some_tag>
<some_tag style="pi">some text here </some_tag>
....
感谢您,如果我写错了什么,也很抱歉,因为我假设您已经有了一些XSLT,这只是一个示例,您可以根据自己的需求进行调整:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="some_tag[@style='blank']">
<div class="{@style}">
<xsl:value-of select="."/>
</div>
</xsl:template>
<xsl:template match="some_tag[./preceding-sibling::some_tag/.[@style='blank']][@style!='blank']">
<xsl:choose>
<xsl:when test="contains(normalize-space(./preceding-sibling::some_tag[1]), 'ten') ">
<p class="{@style}_ten">
<xsl:value-of select="."/>
</p>
</xsl:when>
<xsl:when test="contains(normalize-space(./preceding-sibling::some_tag[1]), 'two') ">
<p class="{@style}_two">
<xsl:value-of select="."/>
</p>
</xsl:when>
<xsl:otherwise>
<p class="{@style}">
<xsl:value-of select="."/>
</p>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
输入XML:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<some_tag style="blank">ten</some_tag>
<some_tag style="p">some text here </some_tag>
<some_tag style="p">some other text here </some_tag>
<some_tag style="blank">two</some_tag>
<some_tag style="pi">some text here </some_tag>
</root>
十
这里有一些文字
这里还有其他一些文字
二
这里有一些文字
输出XML:
<root>
<div class="blank">ten</div>
<p class="p_ten">some text here </p>
<p class="p">some other text here </p>
<div class="blank">two</div>
<p class="pi_two">some text here </p>
</root>
十
这里有一些文字
这里还有其他一些文字
二
这里有一些文字
关于如何使用
的问题-它的使用方式与
类似,但由于这种方法使用
测试十个和两个,因此不需要使用
参考资料:请分享您用XSLT编写的一些代码。您是否使用XSLT 1.0或XSLT 2.0?还没有编写任何代码,只对我可以用XSLT编写感兴趣,我是通过ruby scriptit编写的。它给我XPath错误:无效表达式。/前面的兄弟姐妹::我复制的代码中的某些_标记/[@style='blank']
<root>
<div class="blank">ten</div>
<p class="p_ten">some text here </p>
<p class="p">some other text here </p>
<div class="blank">two</div>
<p class="pi_two">some text here </p>
</root>