如何在XSLT1.0中执行XSLT2.0匹配的等效操作



在几篇文章的帮助下,我已经组装了一个XSLT,并最终使其工作起来。我现在发现处理器只兼容XSLT1.0,这意味着我的XSLT将无法工作,因为它在模板的选择中包含matches函数。

我尝试过几次重新创建它,但用1.0语法替换这一部分时运气不佳。我要么走错了循环,要么做了太多错误的事情。

<xsl:for-each select="../../../*[matches(name(),'^vco_.*')]/text()">
<xsl:value-of select="concat(.,'-')"/>
</xsl:for-each>

我想我可能不得不做下面这样的事情(不起作用),或者使用一个函数,但无法使任何东西看起来正确。

<xsl:for-each select="/exchange/vco/vco.srs/vco_crsc.vco.srs">
<xsl:value-of select="  ancestor-or-self::node()"/>            
<xsl:value-of select="concat(.,'-')"/>
</xsl:for-each>

当前代码和输出遵循

中的XML

<?xml version="1.0" encoding="UTF-8" ?>
<exchange>
<vco>
<vco.srs>
<vco_crsc.vco.srs>BUUBIF</vco_crsc.vco.srs>
<vco_prgc.vco.srs>BUBSBAT02</vco_prgc.vco.srs>
<vco_rouc.vco.srs>USBIFI</vco_rouc.vco.srs>
<cbo>
<cbo.srs>
<cbo_occl.cbo.srs>AJ</cbo_occl.cbo.srs>
<crs>
<crs.srs>
<crs_titl.crs.srs>BSc Banking &amp; Int Finance</crs_titl.crs.srs>
<crs_dptc.crs.srs>B</crs_dptc.crs.srs>
<crs_begd.crs.srs>2003-08-01</crs_begd.crs.srs>
</crs.srs>
</crs>
</cbo.srs>
<cbo.srs>
<cbo_occl.cbo.srs>AJ</cbo_occl.cbo.srs>
<crs>
<crs.srs>
<crs_titl.crs.srs>BSc Banking &amp; Int Finance</crs_titl.crs.srs>
<crs_dptc.crs.srs>B</crs_dptc.crs.srs>
<crs_begd.crs.srs>2003-08-01</crs_begd.crs.srs>
</crs.srs>
</crs>
</cbo.srs>
<cbo.srs>
<cbo_occl.cbo.srs>AJ</cbo_occl.cbo.srs>
<crs>
<crs.srs>
<crs_titl.crs.srs>BSc Banking &amp; Int Finance</crs_titl.crs.srs>
<crs_dptc.crs.srs>B</crs_dptc.crs.srs>
<crs_begd.crs.srs>2003-08-01</crs_begd.crs.srs>
</crs.srs>
</crs>
</cbo.srs>
<cbo.srs>
<cbo_occl.cbo.srs>AJ</cbo_occl.cbo.srs>
<crs>
<crs.srs>
<crs_titl.crs.srs>BSc Banking &amp; Int Finance</crs_titl.crs.srs>
<crs_dptc.crs.srs>B</crs_dptc.crs.srs>
<crs_begd.crs.srs>2003-08-01</crs_begd.crs.srs>
</crs.srs>
</crs>
</cbo.srs>
<cbo.srs>
<cbo_occl.cbo.srs>FJ</cbo_occl.cbo.srs>
<crs>
<crs.srs>
<crs_titl.crs.srs>BSc Banking &amp; Int Finance</crs_titl.crs.srs>
<crs_dptc.crs.srs>B</crs_dptc.crs.srs>
<crs_begd.crs.srs>2003-08-01</crs_begd.crs.srs>
</crs.srs>
</crs>
</cbo.srs>
<cbo.srs>
<cbo_occl.cbo.srs>AJ</cbo_occl.cbo.srs>
<crs>
<crs.srs>
<crs_titl.crs.srs>BSc Banking &amp; Int Finance</crs_titl.crs.srs>
<crs_dptc.crs.srs>B</crs_dptc.crs.srs>
<crs_begd.crs.srs>2003-08-01</crs_begd.crs.srs>
</crs.srs>
</crs>
</cbo.srs>
<cbo.srs>
<cbo_occl.cbo.srs>FJ</cbo_occl.cbo.srs>
<crs>
<crs.srs>
<crs_titl.crs.srs>BSc Banking &amp; Int Finance</crs_titl.crs.srs>
<crs_dptc.crs.srs>B</crs_dptc.crs.srs>
<crs_begd.crs.srs>2003-08-01</crs_begd.crs.srs>
</crs.srs>
</crs>
</cbo.srs>
</cbo>
</vco.srs>
<vco.srs>
<vco_crsc.vco.srs>BUUBIF</vco_crsc.vco.srs>
<vco_prgc.vco.srs>BUBSBAT02</vco_prgc.vco.srs>
<vco_rouc.vco.srs>USBIFA</vco_rouc.vco.srs>
<cbo>
<cbo.srs>
<cbo_occl.cbo.srs>AJ</cbo_occl.cbo.srs>
<crs>
<crs.srs>
<crs_titl.crs.srs>BSc Banking &amp; Int Finance</crs_titl.crs.srs>
<crs_dptc.crs.srs>B</crs_dptc.crs.srs>
<crs_begd.crs.srs>2003-08-01</crs_begd.crs.srs>
</crs.srs>
</crs>
</cbo.srs>
<cbo.srs>
<cbo_occl.cbo.srs>AJ</cbo_occl.cbo.srs>
<crs>
<crs.srs>
<crs_titl.crs.srs>BSc Banking &amp; Int Finance</crs_titl.crs.srs>
<crs_dptc.crs.srs>B</crs_dptc.crs.srs>
<crs_begd.crs.srs>2003-08-01</crs_begd.crs.srs>
</crs.srs>
</crs>
</cbo.srs>
<cbo.srs>
<cbo_occl.cbo.srs>AJ</cbo_occl.cbo.srs>
<crs>
<crs.srs>
<crs_titl.crs.srs>BSc Banking &amp; Int Finance</crs_titl.crs.srs>
<crs_dptc.crs.srs>B</crs_dptc.crs.srs>
<crs_begd.crs.srs>2003-08-01</crs_begd.crs.srs>
</crs.srs>
</crs>
</cbo.srs>
<cbo.srs>
<cbo_occl.cbo.srs>AJ</cbo_occl.cbo.srs>
<crs>
<crs.srs>
<crs_titl.crs.srs>BSc Banking &amp; Int Finance</crs_titl.crs.srs>
<crs_dptc.crs.srs>B</crs_dptc.crs.srs>
<crs_begd.crs.srs>2003-08-01</crs_begd.crs.srs>
</crs.srs>
</crs>
</cbo.srs>
<cbo.srs>
<cbo_occl.cbo.srs>FJ</cbo_occl.cbo.srs>
<crs>
<crs.srs>
<crs_titl.crs.srs>BSc Banking &amp; Int Finance</crs_titl.crs.srs>
<crs_dptc.crs.srs>B</crs_dptc.crs.srs>
<crs_begd.crs.srs>2003-08-01</crs_begd.crs.srs>
</crs.srs>
</crs>
</cbo.srs>
<cbo.srs>
<cbo_occl.cbo.srs>AJ</cbo_occl.cbo.srs>
<crs>
<crs.srs>
<crs_titl.crs.srs>BSc Banking &amp; Int Finance</crs_titl.crs.srs>
<crs_dptc.crs.srs>B</crs_dptc.crs.srs>
<crs_begd.crs.srs>2003-08-01</crs_begd.crs.srs>
</crs.srs>
</crs>
</cbo.srs>
<cbo.srs>
<cbo_occl.cbo.srs>FJ</cbo_occl.cbo.srs>
<crs>
<crs.srs>
<crs_titl.crs.srs>BSc Banking &amp; Int Finance</crs_titl.crs.srs>
<crs_dptc.crs.srs>B</crs_dptc.crs.srs>
<crs_begd.crs.srs>2003-08-01</crs_begd.crs.srs>
</crs.srs>
</crs>
</cbo.srs>
</cbo>
</vco.srs>
</vco>
</exchange>

我的XSL 2.0模板可以实现我想要的功能:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output indent="yes" method="xml"/>
<xsl:template match="/exchange">
<ImportTask xlns="http://inplace.quantumit.com.au/import/version_1_0/" xmlns:i="http://www.w3.org/2001/XMLSchema">
<CourseVersions>
<xsl:for-each select="/exchange/vco/vco.srs">
<CourseVersion>
<xsl:apply-templates select="//cbo_occl.cbo.srs | //crs/crs.srs"/>
</CourseVersion>
</xsl:for-each>
</CourseVersions>
</ImportTask>
</xsl:template>
<xsl:template match="cbo_occl.cbo.srs">
<CourseCode>
<!-- select all text-Nodes of vco_* elements -->
<xsl:for-each select="../../../*[matches(name(),'^vco_.*')]/text()">
<xsl:value-of select="concat(.,'-')"/>
</xsl:for-each>
<xsl:value-of select="."/>
</CourseCode>   
<Version>1</Version>
<EndDate>i:nil="true"</EndDate>
<PrimaryDisciplineCode>i:nil="true"</PrimaryDisciplineCode>
</xsl:template>
<xsl:template match="crs/crs.srs">
<xsl:for-each select="exchange/crs/crs.srs">
</xsl:for-each> 
<StartDate><xsl:value-of select="crs_begd.crs.srs"/></StartDate>
<Description><xsl:value-of select="crs_titl.crs.srs"/></Description>
<FacultyCode><xsl:value-of select="crs_dptc.crs.srs"/></FacultyCode>
</xsl:template>
</xsl:stylesheet>

我想要的输出

<?xml version="1.0" encoding="UTF-8"?>
<ImportTask xmlns:i="http://www.w3.org/2001/XMLSchema"
xlns="http://inplace.quantumit.com.au/import/version_1_0/">
<CourseVersions>
<CourseVersion>
<CourseCode>BUUBIF-BUBSBAT02-USBIFI-AJ</CourseCode>
<Version>1</Version>
<EndDate>i:nil="true"</EndDate>
<PrimaryDisciplineCode>i:nil="true"</PrimaryDisciplineCode>
<StartDate>2003-08-01</StartDate>
<Description>BSc Banking &amp; Int Finance</Description>
<FacultyCode>B</FacultyCode>
<CourseCode>BUUBIF-BUBSBAT02-USBIFI-AJ</CourseCode>
<Version>1</Version>
<EndDate>i:nil="true"</EndDate>
<PrimaryDisciplineCode>i:nil="true"</PrimaryDisciplineCode>
<StartDate>2003-08-01</StartDate>
<Description>BSc Banking &amp; Int Finance</Description>
<FacultyCode>B</FacultyCode>
<CourseCode>BUUBIF-BUBSBAT02-USBIFI-AJ</CourseCode>
<Version>1</Version>
<EndDate>i:nil="true"</EndDate>
<PrimaryDisciplineCode>i:nil="true"</PrimaryDisciplineCode>
<StartDate>2003-08-01</StartDate>
<Description>BSc Banking &amp; Int Finance</Description>
<FacultyCode>B</FacultyCode>
<CourseCode>BUUBIF-BUBSBAT02-USBIFI-AJ</CourseCode>
<Version>1</Version>
<EndDate>i:nil="true"</EndDate>
<PrimaryDisciplineCode>i:nil="true"</PrimaryDisciplineCode>
<StartDate>2003-08-01</StartDate>
<Description>BSc Banking &amp; Int Finance</Description>
<FacultyCode>B</FacultyCode>
<CourseCode>BUUBIF-BUBSBAT02-USBIFI-FJ</CourseCode>
<Version>1</Version>
<EndDate>i:nil="true"</EndDate>
<PrimaryDisciplineCode>i:nil="true"</PrimaryDisciplineCode>
<StartDate>2003-08-01</StartDate>
<Description>BSc Banking &amp; Int Finance</Description>
<FacultyCode>B</FacultyCode>
<CourseCode>BUUBIF-BUBSBAT02-USBIFI-AJ</CourseCode>
<Version>1</Version>
<EndDate>i:nil="true"</EndDate>
<PrimaryDisciplineCode>i:nil="true"</PrimaryDisciplineCode>
<StartDate>2003-08-01</StartDate>
<Description>BSc Banking &amp; Int Finance</Description>
<FacultyCode>B</FacultyCode>
<CourseCode>BUUBIF-BUBSBAT02-USBIFI-FJ</CourseCode>
<Version>1</Version>
<EndDate>i:nil="true"</EndDate>
<PrimaryDisciplineCode>i:nil="true"</PrimaryDisciplineCode>
<StartDate>2003-08-01</StartDate>
<Description>BSc Banking &amp; Int Finance</Description>
<FacultyCode>B</FacultyCode>
<CourseCode>BUUBIF-BUBSBAT02-USBIFA-AJ</CourseCode>
<Version>1</Version>
<EndDate>i:nil="true"</EndDate>
<PrimaryDisciplineCode>i:nil="true"</PrimaryDisciplineCode>
<StartDate>2003-08-01</StartDate>
<Description>BSc Banking &amp; Int Finance</Description>
<FacultyCode>B</FacultyCode>
<CourseCode>BUUBIF-BUBSBAT02-USBIFA-AJ</CourseCode>
<Version>1</Version>
<EndDate>i:nil="true"</EndDate>
<PrimaryDisciplineCode>i:nil="true"</PrimaryDisciplineCode>
<StartDate>2003-08-01</StartDate>
<Description>BSc Banking &amp; Int Finance</Description>
<FacultyCode>B</FacultyCode>
<CourseCode>BUUBIF-BUBSBAT02-USBIFA-AJ</CourseCode>
<Version>1</Version>
<EndDate>i:nil="true"</EndDate>
<PrimaryDisciplineCode>i:nil="true"</PrimaryDisciplineCode>
<StartDate>2003-08-01</StartDate>
<Description>BSc Banking &amp; Int Finance</Description>
<FacultyCode>B</FacultyCode>
<CourseCode>BUUBIF-BUBSBAT02-USBIFA-AJ</CourseCode>
<Version>1</Version>
<EndDate>i:nil="true"</EndDate>
<PrimaryDisciplineCode>i:nil="true"</PrimaryDisciplineCode>
<StartDate>2003-08-01</StartDate>
<Description>BSc Banking &amp; Int Finance</Description>
<FacultyCode>B</FacultyCode>
<CourseCode>BUUBIF-BUBSBAT02-USBIFA-FJ</CourseCode>
<Version>1</Version>
<EndDate>i:nil="true"</EndDate>
<PrimaryDisciplineCode>i:nil="true"</PrimaryDisciplineCode>
<StartDate>2003-08-01</StartDate>
<Description>BSc Banking &amp; Int Finance</Description>
<FacultyCode>B</FacultyCode>
<CourseCode>BUUBIF-BUBSBAT02-USBIFA-AJ</CourseCode>
<Version>1</Version>
<EndDate>i:nil="true"</EndDate>
<PrimaryDisciplineCode>i:nil="true"</PrimaryDisciplineCode>
<StartDate>2003-08-01</StartDate>
<Description>BSc Banking &amp; Int Finance</Description>
<FacultyCode>B</FacultyCode>
<CourseCode>BUUBIF-BUBSBAT02-USBIFA-FJ</CourseCode>
<Version>1</Version>
<EndDate>i:nil="true"</EndDate>
<PrimaryDisciplineCode>i:nil="true"</PrimaryDisciplineCode>
<StartDate>2003-08-01</StartDate>
<Description>BSc Banking &amp; Int Finance</Description>
<FacultyCode>B</FacultyCode>
</CourseVersion>
<CourseVersion>
<CourseCode>BUUBIF-BUBSBAT02-USBIFI-AJ</CourseCode>
<Version>1</Version>
<EndDate>i:nil="true"</EndDate>
<PrimaryDisciplineCode>i:nil="true"</PrimaryDisciplineCode>
<StartDate>2003-08-01</StartDate>
<Description>BSc Banking &amp; Int Finance</Description>
<FacultyCode>B</FacultyCode>
<CourseCode>BUUBIF-BUBSBAT02-USBIFI-AJ</CourseCode>
<Version>1</Version>
<EndDate>i:nil="true"</EndDate>
<PrimaryDisciplineCode>i:nil="true"</PrimaryDisciplineCode>
<StartDate>2003-08-01</StartDate>
<Description>BSc Banking &amp; Int Finance</Description>
<FacultyCode>B</FacultyCode>
<CourseCode>BUUBIF-BUBSBAT02-USBIFI-AJ</CourseCode>
<Version>1</Version>
<EndDate>i:nil="true"</EndDate>
<PrimaryDisciplineCode>i:nil="true"</PrimaryDisciplineCode>
<StartDate>2003-08-01</StartDate>
<Description>BSc Banking &amp; Int Finance</Description>
<FacultyCode>B</FacultyCode>
<CourseCode>BUUBIF-BUBSBAT02-USBIFI-AJ</CourseCode>
<Version>1</Version>
<EndDate>i:nil="true"</EndDate>
<PrimaryDisciplineCode>i:nil="true"</PrimaryDisciplineCode>
<StartDate>2003-08-01</StartDate>
<Description>BSc Banking &amp; Int Finance</Description>
<FacultyCode>B</FacultyCode>
<CourseCode>BUUBIF-BUBSBAT02-USBIFI-FJ</CourseCode>
<Version>1</Version>
<EndDate>i:nil="true"</EndDate>
<PrimaryDisciplineCode>i:nil="true"</PrimaryDisciplineCode>
<StartDate>2003-08-01</StartDate>
<Description>BSc Banking &amp; Int Finance</Description>
<FacultyCode>B</FacultyCode>
<CourseCode>BUUBIF-BUBSBAT02-USBIFI-AJ</CourseCode>
<Version>1</Version>
<EndDate>i:nil="true"</EndDate>
<PrimaryDisciplineCode>i:nil="true"</PrimaryDisciplineCode>
<StartDate>2003-08-01</StartDate>
<Description>BSc Banking &amp; Int Finance</Description>
<FacultyCode>B</FacultyCode>
<CourseCode>BUUBIF-BUBSBAT02-USBIFI-FJ</CourseCode>
<Version>1</Version>
<EndDate>i:nil="true"</EndDate>
<PrimaryDisciplineCode>i:nil="true"</PrimaryDisciplineCode>
<StartDate>2003-08-01</StartDate>
<Description>BSc Banking &amp; Int Finance</Description>
<FacultyCode>B</FacultyCode>
<CourseCode>BUUBIF-BUBSBAT02-USBIFA-AJ</CourseCode>
<Version>1</Version>
<EndDate>i:nil="true"</EndDate>
<PrimaryDisciplineCode>i:nil="true"</PrimaryDisciplineCode>
<StartDate>2003-08-01</StartDate>
<Description>BSc Banking &amp; Int Finance</Description>
<FacultyCode>B</FacultyCode>
<CourseCode>BUUBIF-BUBSBAT02-USBIFA-AJ</CourseCode>
<Version>1</Version>
<EndDate>i:nil="true"</EndDate>
<PrimaryDisciplineCode>i:nil="true"</PrimaryDisciplineCode>
<StartDate>2003-08-01</StartDate>
<Description>BSc Banking &amp; Int Finance</Description>
<FacultyCode>B</FacultyCode>
<CourseCode>BUUBIF-BUBSBAT02-USBIFA-AJ</CourseCode>
<Version>1</Version>
<EndDate>i:nil="true"</EndDate>
<PrimaryDisciplineCode>i:nil="true"</PrimaryDisciplineCode>
<StartDate>2003-08-01</StartDate>
<Description>BSc Banking &amp; Int Finance</Description>
<FacultyCode>B</FacultyCode>
<CourseCode>BUUBIF-BUBSBAT02-USBIFA-AJ</CourseCode>
<Version>1</Version>
<EndDate>i:nil="true"</EndDate>
<PrimaryDisciplineCode>i:nil="true"</PrimaryDisciplineCode>
<StartDate>2003-08-01</StartDate>
<Description>BSc Banking &amp; Int Finance</Description>
<FacultyCode>B</FacultyCode>
<CourseCode>BUUBIF-BUBSBAT02-USBIFA-FJ</CourseCode>
<Version>1</Version>
<EndDate>i:nil="true"</EndDate>
<PrimaryDisciplineCode>i:nil="true"</PrimaryDisciplineCode>
<StartDate>2003-08-01</StartDate>
<Description>BSc Banking &amp; Int Finance</Description>
<FacultyCode>B</FacultyCode>
<CourseCode>BUUBIF-BUBSBAT02-USBIFA-AJ</CourseCode>
<Version>1</Version>
<EndDate>i:nil="true"</EndDate>
<PrimaryDisciplineCode>i:nil="true"</PrimaryDisciplineCode>
<StartDate>2003-08-01</StartDate>
<Description>BSc Banking &amp; Int Finance</Description>
<FacultyCode>B</FacultyCode>
<CourseCode>BUUBIF-BUBSBAT02-USBIFA-FJ</CourseCode>
<Version>1</Version>
<EndDate>i:nil="true"</EndDate>
<PrimaryDisciplineCode>i:nil="true"</PrimaryDisciplineCode>
<StartDate>2003-08-01</StartDate>
<Description>BSc Banking &amp; Int Finance</Description>
<FacultyCode>B</FacultyCode>
</CourseVersion>
</CourseVersions>
</ImportTask>

非常感谢

Jonah

如果您只需要检查固定前缀,那么您可以使用starts-with而不是matches:

<xsl:for-each select="../../../*[starts-with(name(),'vco_')]/text()">

相关内容

  • 没有找到相关文章

最新更新