动态应用XSL模板?

时间:2017-01-19 13:34:50

标签: xml xslt

我有一些XML代码和一个XSLT。在XSLT内部,我有几个模板。 在一种情况下,我需要重新使用XML的已翻译部分第二,第三,......时间。

我在这里有一些示例代码:

    <!-- XML imput -->

<!-- this is a definition -->
<?xml version='1.0' encoding='utf-8'?>
<root>
<pardef id='defId1' keepwithnext='true' keeptogether='true'>
    <code event='hidewhen'>
        <formula>
        Foo=""
        </formula>
    </code>
</pardef>

<!-- the definition is used here by referncing the id -->
<par def='defId1'>
    <field type='text' kind='editable' name='bar'/>
</par>
<!-- and a second one -->
<par def='defId1'>
    <field type='text' kind='editable' name='bar'/>
</par>
</root>

我的XSL:

<!-- XSL -->

<?xml version='1.0' encoding='utf-8'?>
<root>
<!-- template which should be applied -->
<xsl:template match="dxl:field|dxl:sharedfieldref" name="field">
    <!-- do some stuff here -->
</xsl:template>


<!-- ??? cannot be a static name but should compute from the template name (which is pardef) and the given id
<xsl:when test="parent::dxl:par">
    <xsl:apply-templates select="???"/>
</xsl:when>
</root>

结果代码应该是这样的:

<par formula="...">
<field.../>
</par>

<par formula="...">
<field.../>
</par>

我已经有了pardef的模板,应该再次应用。 我希望你能跟着我;-) BTW:我正在使用Webstorm的XSL转换 - 但我无法确定使用哪个处理器。

赞赏Xpath选择器的任何帮助!

0 个答案:

没有答案
相关问题