2013-02-14 2 views
0

XSLT에서 바로 앞으로 XPath 쿼리를 사용하면 목록을 만들 수 있지만 name = something 인 모든 자식 요소의 목록을 만들려면 얻을 수 없습니다. 그것은 작동합니다. 여기 내 XML입니다 :XSLT를 사용하여 Xpath 쿼리에서 순서가 지정되지 않은 목록 만들기

<?xml version="1.0" encoding="UTF-8"?> 

<flights 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:noNamespaceSchemaLocation="flights.xsd"> 

<flight flightid="1"> 
    <flightno>EK98</flightno> 
    <callsign>UAE98</callsign> 
    <airline>Emirates Airline</airline> 

    <plane planeid="1"> 
     <name>Airbus</name> 
     <registereddate>07-06-10</registereddate> 
    </plane> 

    <registration>3A6-EDJ</registration> 
    <altitude height="feet">41000</altitude> 
    <speed ratio="mph">564</speed> 
    <distance unit="miles">erf</distance> 

    <route> 
    <routename>FCO-DXB</routename> 
     <from> 
      <iatacode>FCO</iatacode> 
      <airport>Fiumicino</airport> 
      <country>Italy</country> 
      <city>Rome</city> 
      <latitude>41.8044</latitude> 
      <longitude>12.2508</longitude> 
     </from> 

     <to> 
      <iatacode>DXB</iatacode> 
      <airport>Dubai Intl</airport> 
      <country>UAE</country> 
      <city>Dubai</city> 
      <latitude>25.2528</latitude> 
      <longitude>55.3644</longitude> 
     </to> 
    </route> 

    <course bearing="degrees">154</course> 

    <journey> 
     <distance type="miles">2,697</distance> 
     <time>PT5H30M</time> 
    </journey> 

</flight> 
나는 그것이 에어 버스 같은 경우 비행기/이름 노드의 하위 요소의 텍스트를 포함 정렬되지 않은 목록을 만들려면

.

<?xml version="1.0"?> 
<xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:output method="html" omit-xml-declaration="yes" /> 

<xsl:template match="/"> 
    <xsl:element name="html"> 
     <xsl:element name="head"> 
      <xsl:element name="title">flights</xsl:element> 
     </xsl:element> 

     <xsl:element name="body"> 
      <xsl:element name="ul"> 
       <xsl:attribute name="style"> 
        <xsl:text>width:100px; margin:0 auto; padding: 0;</xsl:text> 
       </xsl:attribute> 
       <xsl:apply-templates select="flights/flight/plane[name='Airbus']"> 

      </xsl:element> 
     </xsl:element> 
    </xsl:element> 

</xsl:template> 


<xsl:template match="name"> 
    <xsl:element name="li"> 
     <xsl:attribute name="style"> 
      <xsl:text>list-style-type:none; width:100px; margin:0 auto;</xsl:text> 
     </xsl:attribute> 

    <xsl:value-of select="name" /> 

    </xsl:element> 
</xsl:template> 



</xsl:stylesheet> 

그래서 결과는 다음과 같이 될 것입니다 : 내가 잘못하시기 바랍니다 하겠어 어디

Name: Airbus 
Registered Date: 07-06-10 

누군가가 나를 보여줄 수 여기에 XSLT 파일에 내 시도는?

답변

1

우선 "리터럴 결과 요소"와 "속성 값 템플릿"이 무엇인지 알아야합니다. 그들은 당신의 XSLT 코드를 훨씬 더 간결하게 만들 것입니다.

귀하의 질문에 답변하십시오 : 요소에 apply-templates을 호출했지만 name 요소와 일치하는 템플릿이 있기 때문에 코드가 작동하지 않습니다. 요소와 일치하는 템플릿을 사용해보십시오.

<xsl:template match="/"> 
    <html> 
     <head> 
      <title>flights</title> 
     </head> 

     <body> 
      <ul style="width:100px; margin:0 auto; padding: 0;"> 
       <xsl:apply-templates select="flights/flight/plane[name='Airbus']"/> 
      </ul> 
     </body> 
    </html> 
</xsl:template> 

<xsl:template match="plane"> 
    <li style="list-style-type:none; width:100px; margin:0 auto;"> 
     <xsl:value-of select="name"/> 
    </li> 
</xsl:template> 
+0

제게 조언 해 주신 데 대해 감사드립니다. – deucalion0

관련 문제