2017-04-15 3 views
0

問題があります。まず、私が使っている言葉が正しい言葉でないならば、私は謝ります。私はXMLにはまったく新しいものです。XSLTファイル内のサブ要素を使用しますか?

私の割り当てでは、DTD、XML、およびXSLTファイルを作成するように求められました。 DTDとXMLファイルが完成しました。私はXSLTファイルを作成しています。すべてが機能しているだけで、他の要素の中にある要素にアクセスする方法はわかりません。ここにコードがありますので、説明しやすくなります。

XML; (例の一部のみ)

<entry id='c01'> 
    <MetaTags>Business</MetaTags> 
    <title><brand>HP Pavilion</brand><name>550-112NA</name></title> 
    <Description>While other towers have been standing still, HP has revolutionized the category. From magnified performance and reliability, to its stylish redesign, this HP Pavilion is the best thing to happen to towers in over 20 years.</Description> 
    <Price>€579</Price> 
    <Image src="Image1.jpg"/> 
    <Specs> 
     <CPU>A10-8750 APU</CPU> 
     <GPU>Radeon R7</GPU> 
     <RAM>8 GB DDR3</RAM> 
     <Storage><HDD> 2TB </HDD></Storage> 
     <OS>Windows 10</OS> 
     <optional> 
      <Monitor>LG 22" Full HD TV</Monitor> 
      <Keyboard>Microsoft Wired Keyboard 600</Keyboard> 
      <Mouse>Logitech M705 Mouse</Mouse>    
     </optional> 
    </Specs> 
</entry> 

XSLT;

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

<html> 
<head> 
    <title>Computer Shop</title> 
</head> 

<body> 
<table border="1"> 
<tr bgcolor="#9acd32"> 

<th style="text-align:left">Image</th> 
<th style="text-align:left">MetaTags</th> 
<th style="text-align:left">Brand</th> 
<th style="text-align:left">Name</th> 
<th style="text-align:left">Description</th> 
<th style="text-align:left">Price</th> 
<th style="text-align:left">CPU</th> 
<th style="text-align:left">GPU</th> 
<th style="text-align:left">RAM</th> 
<th style="text-align:left">HDD</th> 
<th style="text-align:left">SSD</th> 
<th style="text-align:left">OS</th> 
<th style="text-align:left">Monitor</th> 
<th style="text-align:left">Keyboard</th> 
<th style="text-align:left">Mouse</th> 
</tr> 
<xsl:for-each select="ComputerShop/entry"> 
<tr> 

<td> 
<xsl:value-of select="Image"/> 
</td> 

<td> 
<xsl:value-of select="MetaTags"/> 
</td> 

<td> 
<xsl:value-of select="brand"/> 
</td> 

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

<td> 
<xsl:value-of select="Description"/> 
</td> 

<td> 
<xsl:value-of select="Price"/> 
</td> 

<td> 
<xsl:value-of select="RAM"/> 
</td> 

<td> 
<xsl:value-of select="RAM"/> 
</td> 

<td> 
<xsl:value-of select="HDD"/> 
</td> 

<td> 
<xsl:value-of select="SSD"/> 
</td> 

<td> 
<xsl:value-of select="OS"/> 
</td> 

<td> 
<xsl:value-of select="Monitor"/> 
</td> 

<td> 
<xsl:value-of select="Keyboard"/> 
</td> 

<td> 
<xsl:value-of select="Mouse"/> 
</td> 





</tr> 
</xsl:for-each> 
</table> 
</body> 





</html> 
</xsl:template> 
</xsl:stylesheet> 

すべてこれは次のようなものです。

enter image description here

あなたが見ることができるように、別の要素内の任意のXML要素は、テーブル内で表示されません。私はこれをどのように修正することができるかについての助けをしたいと思います。ありがとうございました。

答えて

1

select属性で要素へのパスを指定できます。代わりにこれを行うの

....

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

<xsl:value-of select="Specs/RAM"/> 
同様

、モニターを取得するには、例えば、これを行うRAMSpecs要素の下にあるとしてあなたは、この操作を行う必要があります

<xsl:value-of select="Specs/optional/Monitor"/> 
関連する問題