2014-10-31 7 views
0

Я пытаюсь преобразовать xml-файл, используя xslt stylesheet в html-формат для печати значений. мои файлы .xml выглядит следующим образом:xml to html out using xslt stylesheet

<?xml version="1.0" encoding="UTF-8"?> 
<?xml-stylesheet type= "text/xsl" href="rt.xsl"?> 
<entityset>  
<entity id="32" name="RT: Testing : Testing" hidden="true"> 
    <attribute id="1242" name="Tiketi receiver" code="start_supportGroup"> 
     <value>3.Saldo</value> 
    </attribute> 
    <attribute id="682" name="Kohde" code="store"> 
     <reference id="288799" name="Market"/> 
    </attribute> 
    <attribute id="683" name="Contact" code="person"> 
     <value>[email protected]</value> 
    </attribute> 
    <attribute id="684" name="Puhelinnumero" code="phone"> 
     <value>0505444566</value> 
    </attribute> 
</entity> 
<entity id="32" name="RT: Testing2 : Testing2" hidden="true"> 
    <attribute id="1243" name="Tiketi receiver2" code="start_supportGroup"> 
     <value>4.Saldo</value> 
    </attribute> 
    <attribute id="682" name="Kohde" code="store"> 
     <reference id="288799" name="Market2"/> 
    </attribute> 
    <attribute id="683" name="Contact" code="person"> 
     <value>[email protected]</value> 
    </attribute> 
    <attribute id="684" name="Puhelinnumero" code="phone"> 
     <value>05054445663</value> 
    </attribute> 
</entity> 
</entityset> 

И я хотел бы, чтобы распечатать элементы TD HTML для кода = «» часть в атрибуте. Что-то вроде этого:

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

<xsl:template match="entity"> 
<html> 
<body> 
<h2>RKPP-TIKETIT</h2> 
<table border="1"> 
    <tr bgcolor="#9acd32"> 
    <th style="text-align:left">ID</th> 
    <th style="text-align:left">Kohde</th> 
    <th style="text-align:left">StartSupportgroup</th> 
    </tr> 
    <xsl:for-each select="entity/attribute"> 
    <tr> 
    <td><xsl:for-each select="attribute"> 
    <xsl:attribute name="{@code}" > 
    <xsl:value-of select="."/> 
    </xsl:attribute> 
    </xsl:for-each></td> 
    </tr> 
    </xsl:for-each> 
</table> 
</body> 
</html> 
</xsl:template> 
</xsl:stylesheet> 

Привет я могу добиться этого, пожалуйста, совет.

EDIT: это то, что я хочу добиться:

start_supportgroup store phone 
<td>3.Saldo</td> <td>Market</td>  <td>505444566</td> 
<td>4.Saldo</td> <td>Market2</td> <td>5054445663</td> 

как изображение: http://www.imgrobot.com/image/wUQ

Спасибо,

Toby

+0

У вас есть конкретный вопрос? –

+0

Привет, да. Как распечатать, используя значения html таблицы td для атрибута 4.Saldo user2023042

+0

Оригинальный вопрос, отредактированный с желаемым результатом – user2023042

ответ

1

Если я правильно понимаю, вы хотите что-то вроде:

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

<xsl:template match="/entityset"> 
    <table border="1"> 
     <tr> 
      <th>StartSupportgroup</th> 
      <th>Store</th> 
      <th>Phone</th> 
     </tr> 
     <xsl:apply-templates select="entity"/> 
    </table> 
</xsl:template> 

<xsl:template match="entity"> 
    <tr> 
     <td><xsl:value-of select="attribute[@code='start_supportGroup']/value"/></td> 
     <td><xsl:value-of select="attribute[@code='store']/reference/@name"/></td> 
     <td><xsl:value-of select="attribute[@code='phone']/value"/></td> 
    </tr> 
</xsl:template> 

</xsl:stylesheet> 

Применительно к вашему входу, это вернет:

<?xml version="1.0" encoding="utf-8"?> 
<table border="1"> 
    <tr> 
     <th>StartSupportgroup</th> 
     <th>Store</th> 
     <th>Phone</th> 
    </tr> 
    <tr> 
     <td>3.Saldo</td> 
     <td>Market</td> 
     <td>0505444566</td> 
    </tr> 
    <tr> 
     <td>4.Saldo</td> 
     <td>Market2</td> 
     <td>05054445663</td> 
    </tr> 
</table> 

визуализируется как:

enter image description here

+0

Привет, Майкл, да, это именно то, что я хотел .. для каждой части нет, можете ли вы написать это тоже? – user2023042

+0

@ user2023042 Для каждой части не «отсутствует». Он * исключается *, используя вместо этого шаблоны. –

+0

True .. по какой-то причине он не меняет строки, и это выглядит так в IE http://www.imgrobot.com/images/2014/10/31/output2.jpg – user2023042