0

I'm trying to convert a xml file using xslt stylesheet to html format for printing out values. my .xml files looks like this:

<?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>

And I would like to print out an html td elements for the code="" part in the attribute. Something like this:

<?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>

Hi can I achieve this please advice.

EDIT: this is what I wanna achieve:

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

as image: http://www.imgrobot.com/image/wUQ

Thanks,

Toby

9
  • Do you have a specific question? Commented Oct 31, 2014 at 9:16
  • Hi, yes I have. How do I print out using html table td values of the <attribute id="1243" name="Tiketi receiver2" code="start_supportGroup"> <value>4.Saldo</value> Commented Oct 31, 2014 at 9:27
  • Original question edited with wanted output Commented Oct 31, 2014 at 9:34
  • 1
    Your wanted output does not match your XSLT. And your input sample is not well-formed. Please fix both of these things. Be precise, hand-waving benefits no-one. Commented Oct 31, 2014 at 9:36
  • Do you mean you only want to output attribute elements whose code="start_supportGroup"? Commented Oct 31, 2014 at 9:38

1 Answer 1

1

If I understand correctly, you want something like:

<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>

Applied to your input, this will return:

<?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>

rendered as:

enter image description here

Sign up to request clarification or add additional context in comments.

9 Comments

Hi Michael yes this is exactly what I wanted.. the for each part is missing can you write this also?
@user2023042 The for-each part is not "missing". It is eliminated by using templates instead.
True.. for some reason its not changing the rows and it looks like this in IE imgrobot.com/images/2014/10/31/output2.jpg
How can we fix so it prints a real nice table in IE? Points coming your way
@user2023042 Not sure what you mean "a real nice table". You can add CSS styles to the table (similar to what you had in your XSLT). That's not relevant to your question and I have no interest in doing that.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.