XSLT拆分输出文件

编程入门 行业动态 更新时间:2024-10-11 21:22:10
本文介绍了XSLT拆分输出文件-Muenchian分组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个XSLT文件,以便转换大量数据.我想添加拆分"功能,作为链接的XSLT或在当前的XSLT内,它可以创建多个输出文件,以便将文件的大小限制在一定阈值以下. 假设输入的XML如下:

I have an XSLT file so as to transform large amount of data. I would like to add a "split" functionality, either as a chained XSLT or within the current XSLT that can create multiple output files so as to limit the size of the files under a certain threshold. Let's assume that the input XML is as below:

<People> <Person> <name>John</name> <date>June12</date> <workTime taskID="1">34</workTime> <workTime taskID="2">12</workTime> </Person> <Person> <name>John</name> <date>June13</date> <workTime taskID="1">21</workTime> <workTime taskID="2">11</workTime> </Person> <Person> <name>Jack</name> <date>June19</date> <workTime taskID="1">20</workTime> <workTime taskID="2">30</workTime> </Person> </People>

使用muenchian分组的XSLT文件如下所示.

The XSLT file is as below using muenchian grouping.

<xsl:stylesheet version="1.0" xmlns:xsl="www.w3/1999/XSL/Transform"> <xsl:key name="PersonTasks" match="workTime" use="concat(@taskID, ../name)"/> <xsl:template match="/"> <People> <xsl:apply-templates select="//workTime[generate-id() = generate-id(key('PersonTasks',concat(@taskID, ../name))[1])]"/> </People> </xsl:template> <xsl:template match="workTime"> <xsl:variable name="taskID"> <xsl:value-of select="@taskID"/> </xsl:variable> <xsl:variable name="name"> <xsl:value-of select="../name"/> </xsl:variable> <Person> <name> <xsl:value-of select="$name"/> </name> <taskID> <xsl:value-of select="$taskID"/> </taskID> <xsl:for-each select="//workTime[../name = $name][@taskID = $taskID]"> <workTime> <date> <xsl:value-of select="../date"/> </date> <time> <xsl:value-of select="."/> </time> </workTime> </xsl:for-each> </Person> </xsl:template> </xsl:stylesheet>

但是,我希望将以下几个文件作为输出,而不是一个大文件.对于此示例,我为每个文件仅设置了一个名称..但这应该是一个参数.

However, I'd like ,as an output, several files as below instead of a large one. For this example, I have set only one name per file..but this should be a parameter.

第一人称输出文件:

<People> <Person> <name>John</name> <taskID>1</taskID> <workTime> <date>June12</date> <time>34</time> </workTime> <workTime> <date>June13</date> <time>21</time> </workTime> </Person> <Person> <name>John</name> <taskID>2</taskID> <workTime> <date>June12</date> <time>12</time> </workTime> <workTime> <date>June13</date> <time>11</time> </workTime> </Person> </People>

第二人称输出文件:

<People> <Person> <name>Jack</name> <taskID>1</taskID> <workTime> <date>June19</date> <time>20</time> </workTime> </Person> <Person> <name>Jack</name> <taskID>2</taskID> <workTime> <date>June19</date> <time>30</time> </workTime> </Person> </People>

使用XSLT 1.0首选和最优雅的方法是什么?有没有一种方法可以在XSLT中调用链接的XSLT来拆分输出文件?

What would be the preferred and most elegant approach using XSLT 1.0? Is there a way to call a chained XSLT within the XSLT so as to split the output files?

干杯.

推荐答案

有没有一种方法可以调用链接的XSLT 在XSLT中,以便拆分 输出文件?

Is there a way to call a chained XSLT within the XSLT so as to split the output files?

几种方法:

  • 您可以编写扩展功能来做到这一点-查看XSLT处理器的文档.

  • You could write an extension function to do this -- check the documentation of your XSLT processor.

    使用 <exsl:document> 扩展元素EXSLT ,如果您的XSLT处理器支持的话

    Use the <exsl:document> extension element of EXSLT, in case this is supported by your XSLT processor

    使用 <saxon:output> 扩展元素(如果您有Saxon 6.x

    Use the <saxon:output> extension element if you have Saxon 6.x

    在您的编程语言中循环调用一个单独的转换,将要为其生成结果的人员的姓名作为参数传递给它.

    In a loop from your programming language invoke a separate transformation, passing to it as parameter the name of the person for which to produce results.

    以下是上面2和3的代码示例:

    使用<saxon:output>:

    <xsl:stylesheet version="1.0" xmlns:xsl="www.w3/1999/XSL/Transform" xmlns:saxon="icl/saxon" extension-element-prefixes="saxon" > <xsl:template match="/"> <xsl:for-each select="/*/*[not(. > 3)]"> <saxon:output href="c:\xml\doc{.}"> <xsl:copy-of select="."/> </saxon:output> </xsl:for-each> </xsl:template> </xsl:stylesheet>

    在以下XML文档上应用此转换时:

    <nums> <num>01</num> <num>02</num> <num>03</num> <num>04</num> <num>05</num> <num>06</num> <num>07</num> <num>08</num> <num>09</num> <num>10</num> </nums>

    使用所需的内容创建三个文件:c:\xml\doc1,c:\xml\doc2和c:\xml\doc3.

    three files: c:\xml\doc1 , c:\xml\doc2 and c:\xml\doc3 are created with the wanted contents.

    使用<exslt:document>的相同示例:

    The same example using <exslt:document>:

    <xsl:stylesheet version="1.0" xmlns:xsl="www.w3/1999/XSL/Transform" xmlns:ext="exslt/common" extension-element-prefixes="saxon" > <xsl:template match="/"> <xsl:for-each select="/*/*[not(. > 3)]"> <ext:document href="c:\xml\doc{.}"> <xsl:copy-of select="."/> </ext:document> </xsl:for-each> </xsl:template> </xsl:stylesheet>
  • 更多推荐

    XSLT拆分输出文件

    本文发布于:2023-11-11 05:13:52,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1577474.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:文件   XSLT

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!