2013-04-12 35 views
4

我正试图修改calimero中的ets4_import以匹配旧的ETS4项目和新的项目。XML转换 - XSL模板匹配多个条件

是否有可能修改

<xsl:template match="/" xmlns:b="http://knx.org/xml/project/11"> 

喜欢的东西

<xsl:template match="/" xmlns:b="http://knx.org/xml/project/11 or http://knx.org/xml/project/10"> 

的XML文件是开始

<?xml version="1.0" encoding="utf-8"?> 
<KNX xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" CreatedBy="ETS4" ToolVersion="ETS 4.0.3 (Build 3250)" xmlns="http://knx.org/xml/project/11"> 

<?xml version="1.0"?> 
<KNX xmlns="http://knx.org/xml/project/10" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" CreatedBy="ETS4" ToolVersion="4.0.1387.12605"> 

Here是完整的XSL文件。

任何人都可以帮助我吗?

感谢

UPDATE

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:b10="http://knx.org/xml/project/10" xmlns:b="http://knx.org/xml/project/11" > 
    <xsl:output method="xml" version="1.0" encoding="iso-8859-1" indent="yes"/> 
    <xsl:template match="/"> 
     <xsl:for-each select="b:KNX/b:Project/b:Installations/b:Installation/b:Topology"> 
      <datapoints> 
      <xsl:for-each select="b:Area/b:Line/b:DeviceInstance/b:ComObjectInstanceRefs/b:ComObjectInstanceRef"> 
       <xsl:sort select="b:Connectors/b:Send/@GroupAddressRefId"/> 
       <xsl:if test="not(preceding::b:Connectors/b:Send/@GroupAddressRefId = current()/b:Connectors/b:Send/@GroupAddressRefId)"> 
        <xsl:for-each select="b:Connectors"> 
         <xsl:variable name="verz" select="document(concat(substring(../@RefId,0,7),'/',substring-before(../@RefId, '_O'), '.xml'))/b:KNX/b:ManufacturerData/b:Manufacturer/b:ApplicationPrograms/b:ApplicationProgram/b:Static/b:ComObjectTable/b:ComObject[@Id = ../../b:ComObjectRefs/b:ComObjectRef[@Id = current()/../@RefId]/@RefId]" /> 
         <xsl:variable name="grosse"> 

是否有可能定义

b: = b: | b10: 

,这样我就不必改变整个文件

回答

0

使用XSLT 2.0你可以先改变(或可能甚至剥离)文档的名称空间,然后应用您拥有的巨大模板。在XSLT 1.0中,您可以用*[local-name()='XYZ']代替b:XYZ的所有发生。

3

我想你正在寻找的是这样的:

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:b10="http://knx.org/xml/project/10" xmlns:b11="http://knx.org/xml/project/11"> 
    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> 
    <xsl:template match="b10:MyElement|b11:Element"> 
     <!-- Template code... --> 
    </xsl:template> 
</xsl:stylesheet> 

虽然因为你是匹配的根元素,你一次只能转换一个XML文档,我不太看的问题,因为/将在任何情况下匹配根元素。

+0

也许我做错了什么,但在模板匹配后,我有一个select =“b:KNX/b:Project ...”,它不再工作。 如果我有select =“b11:KNX/b11:Project ...”,它正在工作,但我想使用两个版本。 – mickeyrourkeske

+0

然后,可能你需要的是b10:KNX/b10:Project | b11:KNX/b11:Project,但是可以肯定的是,我需要一个小而完整(非伪)的输入XML示例,期望的输出以及你目前拥有的结果。 – Dabbler