Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
xslt上的复杂引用_Xslt - Fatal编程技术网

xslt上的复杂引用

xslt上的复杂引用,xslt,Xslt,我有源文件: <?xml version="1.0" encoding="UTF-8" ?> <tourcompany id="CMP001" name= "pacific cmp"> <country id="FRA" name="France"> <citylist id="list001" name="CityofFRA"> <city id="CT001" name="Paris"> <destination>

我有源文件:

<?xml version="1.0" encoding="UTF-8" ?> 
<tourcompany id="CMP001" name= "pacific cmp">
<country id="FRA" name="France">
<citylist id="list001" name="CityofFRA">
<city id="CT001" name="Paris">
  <destination>PD1</destination> 
  <destination>PD2</destination> 
  <destination>PD3</destination> 
  <destination>PD4</destination> 
  <destination>PD5</destination> 
  </city>
<city id="CT002" name="Versailles">
  <destination>VD1</destination> 
  <destination>VD2</destination> 
  <destination>VD3</destination> 
  <destination>VD4</destination> 
  <destination>VD5</destination> 
    </city>
  </citylist>
  <zoo id="PD1" name="BurgerZoo" /> 
  <park id="PD2" name="partABC" /> 
  <church id="PD3" name="AtoZchurch" /> 
  <museum id="PD4" name="VANGT">
  <artmuseum/>
  </museum> 
 <museum id="PD5" name="WATER FALL"/>


  <direction_path id="PH123" from="PD1" to="PD3"/>

  <direction_path id="PH124" from="PD3" to="PD2"/>

  <direction_path id="PH125" from="PD2" to="PD4"/>
  <direction_path id="PH126" from="PD4" to="PD5"/>

<zoo id="VD1" name="GDF">
  <bigzoo /> 
</zoo>
<part id="VD2" name="KALA">
  <nationalpart/> 
 </part>
  <part id="VD3" name="Disneyalnd">
  <waterpart/> 
  </part>
<church id="VD4" name="SANT">
<museum id="VD5" name="alibaba">
  <historymuseum/>
  </museum>

  <direction_path id="PH001" from="VD1" to="VD2"/>

  <direction_path id="PH002" from="VD2" to="VD3"/>

  <direction_path id="PH003" from="VD3" to="VD5"/>

  <direction_path id="PH004" from="VD5" to="VD4"/>

 </country>  
 </tourcompany>
<org id='COUNTRY'  class = "COUNTRY">
   <org id="list001" class ="CITYLIST">
   <org><text><fill>CityofFRA</fill></text></org>
  <org id="CT001" class ="CITY" countryID="FRA">
      <org><text><fill>Paris</fill></text></org>
      <org id="PD1" class="ZOO" CityID="CT001">
           <text>BurgerZoo</text>
      </org>
             <org id="PD2" class="PART" CityID="CT001">
    <text>partABC</text>
      </org>
      <org id="PD3" class="CHURCH" CityID="CT001">
    <text>AtoZchurch</text>
      </org>
      <org id="PD4" class="ARTMUSEUM" CityID="CT001">
    <text>VANGT</text>
        </org>
        <org id="DIRECTION_PATH_CT001" class="DIRECTION_PATH">
    <org id="PH123" class="CONNECTION" source="PD1" target="PD3"/>  
     <org id="PH124" class="CONNECTION" source="PD3" target="PD2"/>  
     <org id="PH125" class="CONNECTION" source="PD2" target="PD4"/>  
     <org id="PH126" class="CONNECTION" source="PD4" target="PD5"/>  
   </org>    
   </org>  
   <org id="CT002" class ="CITY" countryID="FRA">
   <org><text><fill>Versailles</fill></text></org>
    <org id="VD1" class="ZOO" CityID="CT002">
       <text>GDF</text>
    </org>
    <org id="VD2" class="NATIONALPART" CityID="CT002">
       <text>KALA</text>
    </org>
    <org id="VD3" class="WATERPART" CityID="CT002">
        <text>Disneyalnd</text>
    </org>
    <org id="VD4" class="CHURCH" CityID="CT002">
       <text>SANT</text>
    </org>
    <org id="VD5" class="HISTORYMUSEUM" CityID="CT002">
     <text>alibaba</text>
    </org>
    <org id="DIRECTION_PATH_CT001" class="DIRECTION_PATH">
      <org id="PH001" class="CONNECTION" source="VD1" target="VD2"/>  
      <org id="PH002" class="CONNECTION" source="VD2" target="VD3"/>  
      <org id="PH003" class="CONNECTION" source="VD3" target="VD5"/>  
        <org id="PH004" class="CONNECTION" source="VD5" target="VD4"/>  
    </org>    
  </org>  
  </org> 
 </org>

PD1
PD2
PD3
PD4
PD5
VD1
VD2
VD3
VD4
VD5

以及目标文件:

<?xml version="1.0" encoding="UTF-8" ?> 
<tourcompany id="CMP001" name= "pacific cmp">
<country id="FRA" name="France">
<citylist id="list001" name="CityofFRA">
<city id="CT001" name="Paris">
  <destination>PD1</destination> 
  <destination>PD2</destination> 
  <destination>PD3</destination> 
  <destination>PD4</destination> 
  <destination>PD5</destination> 
  </city>
<city id="CT002" name="Versailles">
  <destination>VD1</destination> 
  <destination>VD2</destination> 
  <destination>VD3</destination> 
  <destination>VD4</destination> 
  <destination>VD5</destination> 
    </city>
  </citylist>
  <zoo id="PD1" name="BurgerZoo" /> 
  <park id="PD2" name="partABC" /> 
  <church id="PD3" name="AtoZchurch" /> 
  <museum id="PD4" name="VANGT">
  <artmuseum/>
  </museum> 
 <museum id="PD5" name="WATER FALL"/>


  <direction_path id="PH123" from="PD1" to="PD3"/>

  <direction_path id="PH124" from="PD3" to="PD2"/>

  <direction_path id="PH125" from="PD2" to="PD4"/>
  <direction_path id="PH126" from="PD4" to="PD5"/>

<zoo id="VD1" name="GDF">
  <bigzoo /> 
</zoo>
<part id="VD2" name="KALA">
  <nationalpart/> 
 </part>
  <part id="VD3" name="Disneyalnd">
  <waterpart/> 
  </part>
<church id="VD4" name="SANT">
<museum id="VD5" name="alibaba">
  <historymuseum/>
  </museum>

  <direction_path id="PH001" from="VD1" to="VD2"/>

  <direction_path id="PH002" from="VD2" to="VD3"/>

  <direction_path id="PH003" from="VD3" to="VD5"/>

  <direction_path id="PH004" from="VD5" to="VD4"/>

 </country>  
 </tourcompany>
<org id='COUNTRY'  class = "COUNTRY">
   <org id="list001" class ="CITYLIST">
   <org><text><fill>CityofFRA</fill></text></org>
  <org id="CT001" class ="CITY" countryID="FRA">
      <org><text><fill>Paris</fill></text></org>
      <org id="PD1" class="ZOO" CityID="CT001">
           <text>BurgerZoo</text>
      </org>
             <org id="PD2" class="PART" CityID="CT001">
    <text>partABC</text>
      </org>
      <org id="PD3" class="CHURCH" CityID="CT001">
    <text>AtoZchurch</text>
      </org>
      <org id="PD4" class="ARTMUSEUM" CityID="CT001">
    <text>VANGT</text>
        </org>
        <org id="DIRECTION_PATH_CT001" class="DIRECTION_PATH">
    <org id="PH123" class="CONNECTION" source="PD1" target="PD3"/>  
     <org id="PH124" class="CONNECTION" source="PD3" target="PD2"/>  
     <org id="PH125" class="CONNECTION" source="PD2" target="PD4"/>  
     <org id="PH126" class="CONNECTION" source="PD4" target="PD5"/>  
   </org>    
   </org>  
   <org id="CT002" class ="CITY" countryID="FRA">
   <org><text><fill>Versailles</fill></text></org>
    <org id="VD1" class="ZOO" CityID="CT002">
       <text>GDF</text>
    </org>
    <org id="VD2" class="NATIONALPART" CityID="CT002">
       <text>KALA</text>
    </org>
    <org id="VD3" class="WATERPART" CityID="CT002">
        <text>Disneyalnd</text>
    </org>
    <org id="VD4" class="CHURCH" CityID="CT002">
       <text>SANT</text>
    </org>
    <org id="VD5" class="HISTORYMUSEUM" CityID="CT002">
     <text>alibaba</text>
    </org>
    <org id="DIRECTION_PATH_CT001" class="DIRECTION_PATH">
      <org id="PH001" class="CONNECTION" source="VD1" target="VD2"/>  
      <org id="PH002" class="CONNECTION" source="VD2" target="VD3"/>  
      <org id="PH003" class="CONNECTION" source="VD3" target="VD5"/>  
        <org id="PH004" class="CONNECTION" source="VD5" target="VD4"/>  
    </org>    
  </org>  
  </org> 
 </org>

城府
巴黎
汉堡动物园
partABC
阿托舒奇
万格特
凡尔赛宫
GDF
卡拉
迪斯尼乐园
桑特
阿里巴巴

我认识到这方面的三个主要规则。。。但我无法想象转变的方式:

  • 城市中所有具有“目的地id”的元素将成为该“城市”类中的元素子元素。甚至元素之间映射的连接

  • @name变成了文本元素:只有“CITY”和“CITYLIST”再多一层“
    @name
    ”。对于其余元素,可以直接放置:“
    @name

  • 如果元素中有另一个子元素,它将成为新元素。例如:对于“博物馆”,如果它有元素“artmuseum”,那么类名就变成“artmuseum”。而不是“博物馆”

  • 问题是如何检查元素是否包含任何元素以调用相应的模板。因为这些子元素将成为新类,而不是其父类。

    此样式表:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:key name="ById" match="*" use="@id"/>
        <xsl:param name="pLowerCase" select="'qwertyuiopasdfghjklzxcvbnm'"/>
        <xsl:param name="pUpperCase" select="'QWERTYUIOPASDFGHJKLZXCVBNM'"/>
        <xsl:template match="country|citylist|city">
            <org id="{@id}"  class="{translate(name(),$pLowerCase,$pUpperCase)}">
                <xsl:apply-templates select="@name|citylist|city|destination"/>
            </org>
        </xsl:template>
        <xsl:template match="country/@name"/>
        <xsl:template match="citylist/@name|city/@name">
            <org>
                <text>
                    <fill>
                        <xsl:value-of select="."/>
                    </fill>
                </text>
            </org>
        </xsl:template>
        <xsl:template match="destination" name="destination">
            <org id="{.}"
                     class="{translate(name(key('ById',.)
                                              /descendant-or-self::*[last()]),
                                       $pLowerCase,$pUpperCase)}"
                     CityID="{../@id}">
                <text>
                    <xsl:value-of select="key('ById',.)/@name"/>
                </text>
            </org>
        </xsl:template>
        <xsl:template match="destination[last()]">
            <xsl:call-template name="destination"/>
            <org id="DIRECTION_PATH_{../@id}" class="DIRECTION_PATH">
                <xsl:apply-templates 
                 select="../../../direction_path[@from = current()/../destination]"/>
            </org>
        </xsl:template>
        <xsl:template match="direction_path">
            <org id="{@id}" class="CONNECTION" source="{@from}" target="{@to}"/>
        </xsl:template>
    </xsl:stylesheet>
    
    
    
    输出:

    <org id="FRA" class="COUNTRY">
        <org id="list001" class="CITYLIST">
            <org>
                <text>
                    <fill>CityofFRA</fill>
                </text>
            </org>
            <org id="CT001" class="CITY">
                <org>
                    <text>
                        <fill>Paris</fill>
                    </text>
                </org>
                <org id="PD1" class="ZOO" CityID="CT001">
                    <text>BurgerZoo</text>
                </org>
                <org id="PD2" class="PARK" CityID="CT001">
                    <text>partABC</text>
                </org>
                <org id="PD3" class="CHURCH" CityID="CT001">
                    <text>AtoZchurch</text>
                </org>
                <org id="PD4" class="ARTMUSEUM" CityID="CT001">
                    <text>VANGT</text>
                </org>
                <org id="PD5" class="MUSEUM" CityID="CT001">
                    <text>WATER FALL</text>
                </org>
                <org id="DIRECTION_PATH_CT001" class="DIRECTION_PATH">
                    <org id="PH123" class="CONNECTION" source="PD1" target="PD3" />
                    <org id="PH124" class="CONNECTION" source="PD3" target="PD2" />
                    <org id="PH125" class="CONNECTION" source="PD2" target="PD4" />
                    <org id="PH126" class="CONNECTION" source="PD4" target="PD5" />
                </org>
            </org>
            <org id="CT002" class="CITY">
                <org>
                    <text>
                        <fill>Versailles</fill>
                    </text>
                </org>
                <org id="VD1" class="BIGZOO" CityID="CT002">
                    <text>GDF</text>
                </org>
                <org id="VD2" class="NATIONALPART" CityID="CT002">
                    <text>KALA</text>
                </org>
                <org id="VD3" class="WATERPART" CityID="CT002">
                    <text>Disneyalnd</text>
                </org>
                <org id="VD4" class="CHURCH" CityID="CT002">
                    <text>SANT</text>
                </org>
                <org id="VD5" class="HISTORYMUSEUM" CityID="CT002">
                    <text>alibaba</text>
                </org>
                <org id="DIRECTION_PATH_CT002" class="DIRECTION_PATH">
                    <org id="PH001" class="CONNECTION" source="VD1" target="VD2" />
                    <org id="PH002" class="CONNECTION" source="VD2" target="VD3" />
                    <org id="PH003" class="CONNECTION" source="VD3" target="VD5" />
                    <org id="PH004" class="CONNECTION" source="VD5" target="VD4" />
                </org>
            </org>
        </org>
    </org>
    
    
    城府
    巴黎
    汉堡动物园
    partABC
    阿托舒奇
    万格特
    落水
    凡尔赛宫
    GDF
    卡拉
    迪斯尼乐园
    桑特
    阿里巴巴
    
    Hi,要使XML可见,您必须将其格式化为代码(选择XML,然后单击1010图标)-我这样做是为了阅读问题…您必须解释XML文档的含义。它是非常非结构化的,不同兄弟元素(如果有的话)之间的关系也不清楚。请,至少做你的家庭作业,以准确明确的方式定义问题。