Xml XSLT:按多个特征对项进行排序
我想把所有的部分按时段(月、日、周、年……)分别排序。Somme部分具有相同的周期。 我不明白如何加上年和月的区别 我有如下XML数据:Xml XSLT:按多个特征对项进行排序,xml,xslt,Xml,Xslt,我想把所有的部分按时段(月、日、周、年……)分别排序。Somme部分具有相同的周期。 我不明白如何加上年和月的区别 我有如下XML数据: <?xml version='1.0' encoding='UTF-8'?> <chapter> <title>Title of chapter </title> <section> <title> Title of section 2</title> <pa
<?xml version='1.0' encoding='UTF-8'?>
<chapter>
<title>Title of chapter </title>
<section>
<title> Title of section 2</title>
<para>Period is 2 year </para>
</section>
<section>
<title> Title of section 1</title>
<para>Period is 1 year </para>
</section>
<section>
<title> Title of section 3</title>
<para>Period is 1 week </para>
</section>
<section>
<title> Title of section 4</title>
<para>Period is 1 year </para>
</section>
</chapter>
章名
第2节的标题
期限为2年
第1节的标题
期限为1年
第3条的标题
周期为1周
第4条的标题
期限为1年
我需要这样的结果:
<?xml version='1.0' encoding='UTF-8'?>
<chapter>
<title>Title of chapter </title>
<section>
<title> List elem of 1 week</title>
<section>
<title> Title of section 3</title>
<para>Period is 1 week </para>
</section>
</section>
<section>
<title> List elem of 1 year</title>
<section>
<title> Title of section 1</title>
<para>Period is 1 year </para>
</section>
<section>
<title> Title of section 4</title>
<para>Period is 1 year </para>
</section>
</section>
<section>
<title> List elem of 2 years </title>
<section>
<title> Title of section 2</title>
<para>Period is 2 years </para>
</section>
</section>
</chapter>
章名
列出1周的要素
第3条的标题
周期为1周
列出1年的要素
第1节的标题
期限为1年
第4条的标题
期限为1年
列出两年的基本要素
第2节的标题
期限为2年
我的XSLT如下所示:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:strip-space elements="*"/>
<xsl:template match="node( ) | @*">
<xsl:copy>
<xsl:apply-templates select="@* | node( )"/>
</xsl:copy>
</xsl:template>
<xsl:variable name="liste_valeurs" select="//para[not(. = preceding::para)]"/>
<xsl:template match="chapter">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:for-each select="$liste_valeurs">
<xsl:sort select="." data-type="number"/>
<xsl:variable name="valeur" select="."/>
<xsl:element name="section">
<title> List elem of <xsl:value-of select="$valeur"/></title>
<xsl:apply-templates select="//para[.=$valeur]">
<xsl:call-template name="copie_identique"/>
</xsl:apply-templates>
</xsl:element>
</xsl:for-each>
</xsl:copy>
</xsl:template>
<xsl:template name="copie_identique">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
列表元素
我没有得到预期的结果,我对XSLT非常陌生,如果答案已经存在,请原谅,我搜索了,但我有点迷路了,我不知道到底要搜索什么
我不知道去哪里,也许这个方法不是实现我想要的最好的方法
感谢您提供的任何帮助,这并不简单。考虑下面的例子: XML
<chapter>
<title>Title of chapter </title>
<section>
<title> Title of section 1</title>
<para>Period is 2 years </para>
</section>
<section>
<title> Title of section 2</title>
<para>Period is 3 weeks </para>
</section>
<section>
<title> Title of section 3</title>
<para>Period is 10 months </para>
</section>
<section>
<title> Title of section 4</title>
<para>Period is 1 year </para>
</section>
<section>
<title> Title of section 5</title>
<para>Period is 1 week </para>
</section>
<section>
<title> Title of section 6</title>
<para>Period is 2 months </para>
</section>
</chapter>
章名
第1节的标题
期限为2年
第2节的标题
周期为3周
第3条的标题
期限为10个月
第4条的标题
期限为1年
第5条的标题
周期为1周
第6条的标题
期限为2个月
XSLT1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="chapter">
<xsl:copy>
<xsl:copy-of select="title"/>
<xsl:for-each select="section">
<xsl:sort select="number(contains(para, 'week'))" data-type="number" order="descending"/>
<xsl:sort select="number(contains(para, 'month'))" data-type="number" order="descending"/>
<xsl:sort select="number(contains(para, 'year'))" data-type="number" order="descending"/>
<xsl:sort select="translate(para, translate(para, '0123456789', ''), '')" data-type="number"/>
<xsl:copy-of select="."/>
</xsl:for-each>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
结果
<?xml version="1.0" encoding="UTF-8"?>
<chapter>
<title>Title of chapter </title>
<section>
<title> Title of section 5</title>
<para>Period is 1 week </para>
</section>
<section>
<title> Title of section 2</title>
<para>Period is 3 weeks </para>
</section>
<section>
<title> Title of section 6</title>
<para>Period is 2 months </para>
</section>
<section>
<title> Title of section 3</title>
<para>Period is 10 months </para>
</section>
<section>
<title> Title of section 4</title>
<para>Period is 1 year </para>
</section>
<section>
<title> Title of section 1</title>
<para>Period is 2 years </para>
</section>
</chapter>
章名
第5条的标题
周期为1周
第2节的标题
周期为3周
第6条的标题
期限为2个月
第3条的标题
期限为10个月
第4条的标题
期限为1年
第1节的标题
期限为2年
如果要按
段落对部分进行分组,请研究。是否每个段落都遵循相同的“句点是”
?是的所有@para都遵循相同的模式