2016-03-26 21 views
1

XML'ime öznitelikleri ekledim ve araç özniteliklerini görüntüleyebilmek için XSL dosyasını düzenlemem gerekiyor, XML'de nasıl görebileceğimi nasıl düzenleyebilirim. Eğer ben farklı yöntemler çalışıyordu ilerlemek XML'de XSL öznitelikleri nasıl görüntülenir

<?xml version="1.0" encoding="utf-8" ?> 
 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml"> 
 

 
    <xsl:template match="CarCatalog"> 
 

 
     <xsl:for-each select="CarItem"> 
 
      <span style="font-style: italic; color: blue;"> Year: </span> 
 
      <xsl:value-of select="year" /> 
 
      <br /> 
 
      <span style="font-style: italic; color: blue;"> Make: </span> 
 
      <xsl:value-of select="make" /> 
 
      <br /> 
 
      <span style="font-style: italic; color: blue;"> Model: </span> 
 
      <xsl:value-of select="model" /> 
 
      <br /> 
 
      <span style="font-style: italic; color: blue;"> Color: </span> 
 
      <xsl:value-of select="color" /> 
 
      <br /> 
 
      <span style="font-style: italic; color: blue;"> Engine: </span> 
 
      <xsl:value-of select="engine" /> 
 
      <br /> 
 
      <span style="font-style: italic; color: blue;"> Number of doors: </span> 
 
      <xsl:value-of select="number_of_doors" /> 
 
      <br /> 
 
      <span style="font-style: italic; color: blue;"> Transmission type: </span> 
 
      <xsl:value-of select="transmission_type" /> 
 
      <br /> 
 
    <!-- Here I got stock -->   
 
      <span style="font-style: italic; color: blue;"> Radio: </span> 
 
      <xsl:attribute name="accessories"> 
 
       <xsl:value-of select="." /> 
 
      </xsl:attribute> 
 

 

 
      <br /> 
 
      <br /> 
 
     </xsl:for-each> 
 
    </xsl:template> 
 
</xsl:stylesheet>
ederiz ama yapamıyorum:

<?xml version = "1.0" encoding = "utf-8" ?> 
 
<?xml-stylesheet type = "text/xsl" href = "7.5.xsl" ?> 
 
<CarCatalog> 
 
    <CarItem> 
 
     <make>Nissan</make> 
 
     <model>Altima</model> 
 
     <year>2016</year> 
 
     <color>Red</color> 
 
     <engine> 
 
      <number_of_cylinders>6</number_of_cylinders> 
 
      <fuel_system>fuel</fuel_system> 
 
     </engine> 
 
     <number_of_doors>4</number_of_doors> 
 
     <transmission_type>Auto</transmission_type> 
 
     <accessories radio="Yes" air_conditioning="Yes" power_windows="Yes" Power_steering="Yes" Power_brakes="No" /> 
 
    </CarItem> 
 
</CarCatalog>

Bu XSL parçasıdır: Bu benim XML çalışmasını sağla.

cevap

1

Ne aradığınız olduğunu: Bu arada <xsl:value-of select="accessories/@radio" />

0

, senin süreleri aynıdır ve ortaya çıkan metin orijinal düğüm adıyla eşleşen verilen sizin XSLT genelleme odada <xsl:for-loop> olmadan vardır:

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

    <xsl:template match="CarCatalog" priority="2"> 
    <html> 
     <body> 
      <div> 
       <xsl:apply-templates select="*"/> 
      </div> 
     </body> 
    </html> 
    </xsl:template>  

    <xsl:template match="CarItem" priority="3"> 
     <xsl:apply-templates /> 
    </xsl:template> 

    <xsl:template match="CarItem/*[node()]|accessories/@*" priority="4">   
      <span style="font-style: italic; color: blue;"> 
       <xsl:value-of select="concat(translate(name(.),'_',' '), ': ')"/> 
      </span> 
      <xsl:value-of select="." />      
      <br /> 
    </xsl:template>  

    <xsl:template match="accessories" priority="5"> 
     <xsl:apply-templates select="@*"/> 
    </xsl:template> 

</xsl:stylesheet> 

Çıkış