当源xml很长时,xslt eclipse工具会挂起

时间:2014-01-09 17:27:25

标签: xml eclipse xslt xslt-1.0

我是xslt的新手。我正在使用Eclipse来运行和调试我的XSLT。为此,我安装了以下eclipse插件:

enter image description here

一切似乎都能正常工作,我可以测试我的转换,但有时转换似乎停滞不前,永远不会完成。通过删除一些元素,我可以通过减少测试源文件来解决这个问题。这样转型似乎工作正常。

当然我已经尝试删除不同的元素,以便查看哪一个导致转换停止,但唯一真正影响此问题的因素是源xml文件的大小。

有没有人在遇到这个问题之前?

供您参考,这是我的转换,(由于体长限制,我无法添加示例源XML文件,但我已经放置了一个带有两个示例XML文件的zip文件来处理。它们只是另一个的较短版本,longuer只是拖延较短的一个工作正常https://dl.dropboxusercontent.com/u/4952440/samplesourcexml.zip

XSLT文件

<?xml version="1.0" encoding="UTF-8"?>
<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" />

<!-- Identity to copy all elements -->
<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()" />
    </xsl:copy>
</xsl:template>

<xsl:template name="copyElementAttributes">
    <!-- Copy all element attributes to the renamed element -->
    <xsl:for-each select="@*">
        <xsl:attribute name="{name(.)}"><xsl:value-of select="." />    </xsl:attribute>
    </xsl:for-each>
</xsl:template>

<!-- This takes care of tansformation 1.a -->
<xsl:template match="sec">
    <xsl:element name="sec{count(ancestor::sec)}">
        <xsl:apply-templates select="@*|node()" />
    </xsl:element>
</xsl:template>
<!-- This takes care of transformation 1.b and 1.c -->
<xsl:template match="title">
    <xsl:variable name="titlenumbering">
        <xsl:number level="multiple" count="sec" />
    </xsl:variable>
    <xsl:element name="title{count(ancestor::sec)}">
        <!-- <xsl:apply-templates select="*" /> <xsl:element name="numeracio{count(ancestor::sec)}"> 
            <xsl:value-of select="$titlenumbering" /> </xsl:element> -->
        <xsl:apply-templates select="@*|node()" />
    </xsl:element>
</xsl:template>
<!-- Match p elements where the first preceding sibling is a title element. -->
<!-- this takes care of transformation 4. <p_title> -->
<xsl:template match="p">
    <xsl:variable name="prelativepos">
        <xsl:number level="single" />
    </xsl:variable>
    <xsl:variable name="pabsolutepos">
        <xsl:number level="any" count="/article/body//p" />
    </xsl:variable>
    <xsl:choose>
        <!-- This takes care of transformation 3. <p_first> -->
        <xsl:when test="$pabsolutepos = 1">
            <xsl:element name="p_first">
                <xsl:apply-templates select="@*|node()" />
            </xsl:element>
        </xsl:when>
        <xsl:when test="$prelativepos = 1">
            <p_title>
                <xsl:call-template name="copyElementAttributes" />
                <xsl:apply-templates select="node()|@*" />
            </p_title>
        </xsl:when>
        <xsl:otherwise>
            <xsl:copy>
                <xsl:apply-templates select="@*|node()" />
            </xsl:copy>
        </xsl:otherwise>
    </xsl:choose>

</xsl:template>

<!-- This takes care of transformation 5. <p_list> -->
<xsl:template match="list/p">
    <p_list>
        <xsl:call-template name="copyElementAttributes" />
        <xsl:apply-templates select="node()|@*" />
    </p_list>
</xsl:template>

<!-- Change <p> inside <abstract> to <p_abstract> -->
<xsl:template match="//abstract/p">
    <p_abstract>
        <xsl:call-template name="copyElementAttributes" />
        <xsl:apply-templates select="node()|@*" />
    </p_abstract>
</xsl:template>

<!-- This takes care of transformation 6. <p_bullet> -->
<xsl:template match="list[@list-type='bullet']/p">
    <p_bullet>
        <xsl:call-template name="copyElementAttributes" />
        <xsl:apply-templates select="node()|@*" />
    </p_bullet>
</xsl:template>

<!-- This takes care of transformation 7. <p_simple> -->
<xsl:template match="list[@list-type='simple']/p">
    <p_simple>
        <xsl:call-template name="copyElementAttributes" />
        <xsl:apply-templates select="node()|@*" />
    </p_simple>
</xsl:template>

<!-- This takes care of transformation 8. <p_ordered> -->
<xsl:template match="list[@list-type='ordered']/p">
    <p_ordered>
        <xsl:call-template name="copyElementAttributes" />
        <xsl:apply-templates select="node()|@*" />
    </p_ordered>
</xsl:template>


<!-- Transformation 9. still has to be taken care of -->
<!-- Must clarify with customer how is avanttitle present in the xml -->

<!-- Transformation 10. still has to be taken care of -->
<!-- Must clarify with customer how is subtitle present in the xml -->

<!-- This takes care of transfomration 11. Entradeta <p content_type="entradeta"> -->
<xsl:template match="p[@content-type='entradeta']">
    <entradeta>
        <xsl:call-template name="copyElementAttributes" />
        <xsl:apply-templates select="node()|@*" />
    </entradeta>
</xsl:template>


<!-- This takes care of 12. <title> rigth after title to <title#nospace> -->
<xsl:template match="//title[preceding-sibling::*[1][self::title]]">
    <xsl:element name="title{count(ancestor::sec)}nospace">
        <xsl:apply-templates select="node()|@*" />
    </xsl:element>
</xsl:template>

<!-- This deals with bibliographical references <label> filled with sequence 
    number. rule 13 -->
<xsl:template match="//back/ref-list/ref/label">
    <xsl:variable name="labelval" select="." />
    <label>
        <xsl:call-template name="copyElementAttributes" />
        <xsl:value-of select="count(preceding::ref)+1" />
        <!-- <xsl:apply-templates select="node()|@*"/> -->
    </label>
</xsl:template>

<!-- Replace xref by the number in lable and define as bibliographic xreference. 
    Rule 13 -->
<xsl:template match="//xref[@ref-type='bibr']">
    <xsl:variable name="rid" select="@rid" />
    <biblio_xref>
        <xsl:call-template name="copyElementAttributes" />
        <xsl:attribute name="rid">
            <xsl:value-of select="$rid" />
        </xsl:attribute>
        <xsl:value-of
            select="count(//ref-list/ref[@id=$rid]/preceding-sibling::ref)+1" />
    </biblio_xref>
</xsl:template>

<!-- Deal with tags inside the statemenet tag. Rule 14 -->
<xsl:template match="//statement/p">
    <p_statement>
        <xsl:call-template name="copyElementAttributes" />
        <xsl:apply-templates select="node()|@*" />
    </p_statement>
</xsl:template>
<xsl:template match="//statement/title">
    <statement_author>
        <xsl:call-template name="copyElementAttributes" />
        <xsl:apply-templates select="node()|@*" />
    </statement_author>
</xsl:template>

<!-- <label> inside of <fig> must be tranformed to <pfignum> and must contain 
    figure sequence number. rule 15 and rule 2.a -->
<xsl:template match="//fig/label">
    <pfignum>
        <xsl:call-template name="copyElementAttributes" />
        <xsl:value-of select="count(preceding::fig)+1" />
    </pfignum>
</xsl:template>

<!-- <title> inside <caption> transformed to <pfigtext>. Rule 16 -->
<xsl:template match="//caption/title">
    <pfigtext>
        <xsl:call-template name="copyElementAttributes" />
        <xsl:apply-templates select="node()|@*" />
    </pfigtext>
</xsl:template>

<!-- Replace xref of type figure by the number in lable and define as figure 
    xreference. rule 23 -->
<xsl:template match="//xref[@ref-type='fig']">
    <xsl:variable name="rid" select="@rid" />
    <fig_xref>
        <xsl:call-template name="copyElementAttributes" />

        <xsl:value-of select="count(//fig[@id=$rid]/preceding-sibling::fig)+1" />
    </fig_xref>
</xsl:template>



<!-- Tables transformes into indesign namespace. rule 17 -->
<xsl:template match="//table">
    <xsl:attribute name="xmlns:aid">http://ns.adobe.com/AdobeInDesign/4.0/</xsl:attribute>
    <xsl:attribute name="xmlns:aid5">http://ns.adobe.com/AdobeInDesign/5.0/</xsl:attribute>
</xsl:template>

<!-- <label> inside <table-wrap> transfomed to <tablenum> and secuence order 
    added in tablenum element. rule 18 -->
<xsl:template match="//table-wrap/label">
    <tablenum>
        <xsl:call-template name="copyElementAttributes" />
        <xsl:value-of select="count(preceding::table-wrap)+1" />
    </tablenum>
</xsl:template>

<!-- <caption> inside <table-wrap> transformed to <tablecaption>. rule 19 -->
<xsl:template match="//table-wrap">
    <tablecaption>
        <xsl:call-template name="copyElementAttributes" />
        <xsl:apply-templates select="node()|@*" />
    </tablecaption>
</xsl:template>

<!-- Pending to implement rules 20 (Table related transformations) -->

<!-- Boxed text inside the <boxed_text> :Rule 21 <title> transformed to 
    <boxed_text_title> <label> transformed to <boxed_text_label> <p> transformed 
    to <boxed_text_p> -->

<xsl:template match="//boxed_text/title">
    <boxed_text_title>
        <xsl:call-template name="copyElementAttributes" />
        <xsl:apply-templates select="node()|@*" />
    </boxed_text_title>
</xsl:template>
<xsl:template match="//boxed_text/label">
    <boxed_text_label>
        <xsl:call-template name="copyElementAttributes" />
        <xsl:apply-templates select="node()|@*" />
    </boxed_text_label>
</xsl:template>
<xsl:template match="//boxed_text/p">
    <boxed_text_p>
        <xsl:call-template name="copyElementAttributes" />
        <xsl:apply-templates select="node()|@*" />
    </boxed_text_p>
</xsl:template>

<!-- For foot notes, <p> inside <fn> inside <fn-group> transformed into 
    <boxed_text_footnote>. Rule 22 -->
<xsl:template match="//fn-group/fn/p">
    <boxed_text_footnote>
        <xsl:call-template name="copyElementAttributes" />
        <xsl:apply-templates select="node()|@*" />
    </boxed_text_footnote>
</xsl:template>

<!-- Xref to tables transformed to <tab_xref> and corresponding table number 
    . rule 24 -->
<xsl:template match="//xref[@ref-type='tab']">
    <xsl:variable name="rid" select="@rid" />
    <tab_xref>
        <xsl:call-template name="copyElementAttributes" />
        <xsl:value-of
            select="count(//table-wrap[@id=$rid]/preceding-sibling::table-wrap)+1" />
    </tab_xref>
</xsl:template>
  </xsl:stylesheet>

0 个答案:

没有答案