首页 \ 问答 \ XSLT 1.0在另一个模板的结果上应用模板(XSLT 1.0 apply template on result of another template)

XSLT 1.0在另一个模板的结果上应用模板(XSLT 1.0 apply template on result of another template)

我在XSL中有2个模板,我想在一个XSL文件中执行。 原始的xml

<root>
    <step1.alfa/>
    <step1.bravo/>
    <step1.charlie/>
    <step1.delta/>
    <step2.alfa/>
    <step2.bravo/>
    <step2.charlie/>
    <step2.delta/>

这需要嵌套,然后重命名元素名称。 但我无法弄清楚如何在1个单独的xslt中完成这两个模板。 由于模板始终从原始xml开始。
第一个输出

<root>
<step>
    <step1.alfa/>
    <step1.bravo/>
    <step1.charlie/>
    <step1.delta/>
</step>
<step>
    <step2.alfa/>
    <step2.bravo/>
    <step2.charlie/>
    <step2.delta/>
</step>

第二输出

<root>
<step>
    <alfa/>
    <bravo/>
    <charlie/>
    <delta/>
</step>
<step>
    <alfa/>
    <bravo/>
    <charlie/>
    <delta/>
</step>

第一个模板是嵌套步骤,第二个是重命名它们。 我只显示一个,但我有一个模板,每个元素都需要重命名。

<xsl:template match="Values" name="recursive-steps">
    <xsl:param name="var" select="2"/>
    <xsl:choose>
        <xsl:when test="$var > 0">
            <STEP>

                <xsl:for-each select="node()[starts-with(name(), concat('step', $var))]">
                    <xsl:copy-of select="."/>
                </xsl:for-each>
            </STEP>
            <xsl:call-template name="recursive-steps">
                <xsl:with-param name="var" select="$var - 1"/>
            </xsl:call-template>

        </xsl:when>
        <xsl:otherwise/>
    </xsl:choose>
</xsl:template>

<xsl:template match="*[substring(name(), string-length(name())-3) = 'alfa']">
    <ALFA>
        <xsl:apply-templates select="@*|node()" />
    </ALFA>
</xsl:template>

在这里添加了我想要组合的2个模板。


I have 2 templates in XSL that I want to execute in a single XSL file. Original xml

<root>
    <step1.alfa/>
    <step1.bravo/>
    <step1.charlie/>
    <step1.delta/>
    <step2.alfa/>
    <step2.bravo/>
    <step2.charlie/>
    <step2.delta/>

This needs to be nested and then rename the element names. But I can't figure out how to do those 2 templates in 1 single xslt. As the templates always start from the original xml.
First output

<root>
<step>
    <step1.alfa/>
    <step1.bravo/>
    <step1.charlie/>
    <step1.delta/>
</step>
<step>
    <step2.alfa/>
    <step2.bravo/>
    <step2.charlie/>
    <step2.delta/>
</step>

Second output

<root>
<step>
    <alfa/>
    <bravo/>
    <charlie/>
    <delta/>
</step>
<step>
    <alfa/>
    <bravo/>
    <charlie/>
    <delta/>
</step>

First template is to nest the steps and second is to rename them. I only show one, but I have a template for every element that needs to be renamed.

<xsl:template match="Values" name="recursive-steps">
    <xsl:param name="var" select="2"/>
    <xsl:choose>
        <xsl:when test="$var > 0">
            <STEP>

                <xsl:for-each select="node()[starts-with(name(), concat('step', $var))]">
                    <xsl:copy-of select="."/>
                </xsl:for-each>
            </STEP>
            <xsl:call-template name="recursive-steps">
                <xsl:with-param name="var" select="$var - 1"/>
            </xsl:call-template>

        </xsl:when>
        <xsl:otherwise/>
    </xsl:choose>
</xsl:template>

<xsl:template match="*[substring(name(), string-length(name())-3) = 'alfa']">
    <ALFA>
        <xsl:apply-templates select="@*|node()" />
    </ALFA>
</xsl:template>

Added the 2 templates here that I want to combine.


原文:https://stackoverflow.com/questions/39143066
更新时间:2023-04-27 12:04

最满意答案

有几件事要尝试。

在对话框中的iframe中加载chartpage.htm(我自己没试过,但值得一试):

<div style="display:none" id="chartDlg"><iframe src="chartpage.htm"></iframe></div>

并将功能更改为:

function openchart() {
w = $(window).width() - 100;
h = $(window).height() - 100;
$("#chartDlg").dialog({ modal: true, width: w, height: h, title: 'MyChart', position: 'center' });
$("#chartDlg").dialog('open');
}

要么

将google javascript添加到mainpage.htm:

<script type="text/javascript" src="http://www.google.com/jsapi"></script>

Couple of things to try.

Load chartpage.htm in an iframe in the dialog (haven't tried this myself but worth a shot):

<div style="display:none" id="chartDlg"><iframe src="chartpage.htm"></iframe></div>

and change the function to:

function openchart() {
w = $(window).width() - 100;
h = $(window).height() - 100;
$("#chartDlg").dialog({ modal: true, width: w, height: h, title: 'MyChart', position: 'center' });
$("#chartDlg").dialog('open');
}

OR

Add the google javascript to the mainpage.htm:

<script type="text/javascript" src="http://www.google.com/jsapi"></script>

相关问答

更多
  • 毫无疑问,我选择由Google API服务器提供JQuery。 我没有使用jsapi方法,因为我没有利用任何其他的Google API,但是如果改变了,那么我会考虑它... 第一: Google api服务器分布在世界各地,而不是我的单一服务器位置:更接近的服务器通常意味着访问者的响应时间更快。 第二:许多人选择在Google上托管JQuery,所以当访问者访问我的网站时,他们可能已经在他们的本地缓存中有JQuery脚本。 预先缓存的内容通常意味着访问者的加载时间更快。 第三:我的虚拟主机公司收取使用的带宽 ...
  • 我对这个问题很好奇,因为我问自己完全一样。 我希望你的意思是你没有在Sources选项卡中看到它,因为andyb说它出现在Network选项卡中,但是没有机会调试动态添加的文件。 经过一些谷歌搜索后,我偶然发现了一个堆栈溢出线程问一个类似的问题。 以下是他们提出的建议: 如果要设置断点,只需添加debugger; 在你想拥有它的那一行。 如果整个文件应列在“源”选项卡中,则可以添加 //@ sourceURL=myfile.js //or //@ sourceURL=path/to/js/myfile.j ...
  • 经过一段时间的测试后发现它只能在jquery 1.11.2中正常工作。 点击已经注册,因此在测试期间没有损失任何收入。 After a fair bit of testing it turns out that it works fine off just jquery 1.11.2. Clicks have been registering so didn't lose any earnings during the testing period.
  • google.load()使用document.write() (这样它可以立即加载JS,所以后面的代码不需要回调),所以它只能在文档仍然呈现时同步调用。 您只能直接在