473,705 Members | 2,446 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

question about create table by using xslt

Lee
I have a xml file, here is sample part:
<?xml version="1.0" encoding="UTF-8"?>
<ProducsList>
<Product id="1">
<SpecList>
<Spec>
<SpecLabel>Heig ht</SpecLabel>
<SpecValue>10 </SpecValue>
<SpecCat>Dimens ion</SpecCat>
</Spec>
<Spec>
<SpecLabel>Widt h</SpecLabel>
<SpecValue>6</SpecValue>
<SpecCat>Dimens ion</SpecCat>
</Spec>
<Spec>
<SpecLabel>Weig ht</SpecLabel>
<SpecValue>20.5 </SpecValue>
<SpecCat>Weigth </SpecCat>
</Spec>
</SpecList>
</Prodcut>
<Product id="2">
<SpecList>
<Spec>
<SpecLabel>Heig ht</SpecLabel>
<SpecValue>8</SpecValue>
<SpecCat>Dimens ion</SpecCat>
</Spec>
<Spec>
<SpecLabel>Widt h</SpecLabel>
<SpecValue>5</SpecValue>
<SpecCat>Dimens ion</SpecCat>
</Spec>
<Spec>
<SpecLabel>Weig ht</SpecLabel>
<SpecValue>18 </SpecValue>
<SpecCat>Weigth </SpecCat>
</Spec>
</SpecList>
</Prodcut>
<Product id="3">
<SpecList>
<Spec>
<SpecLabel>Heig ht</SpecLabel>
<SpecValue>5</SpecValue>
<SpecCat>Dimens ion</SpecCat>
</Spec>
<Spec>
<SpecLabel>Widt h</SpecLabel>
<SpecValue>2</SpecValue>
<SpecCat>Dimens ion</SpecCat>
</Spec>
<Spec>
<SpecLabel>Weig ht</SpecLabel>
<SpecValue>10 </SpecValue>
<SpecCat>Weigth </SpecCat>
</Spec>
</SpecList>
</Prodcut>
</ProductsList>

I need to create a table look like that based on that xml file:

----------------------------------------------------
Label Product 1 product 2 product 3
----------------------------------------------------
Height 10 8 5
Width 6 5 2
Weight 20.5 18 10

I am totally losed, I don't know how to create that table. any one has
any idea about that? thank you very much.

Also how many Spec in SpecList is unkown.

Thanks for the help.

May 31 '07 #1
5 3726
here it is
<?xml version="1.0" encoding="utf-8"?>

<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
<html>

<body>
<!--
This is an XSLT template file. Fill in this area with the
XSL elements which will transform your XML to XHTML.
-->
<table>
<tr>
<th>Label</th>
<xsl:for-each select="Product sList/Product">
<th>
<xsl:value-of select="concat( 'Product',@id)"/>
</th>
</xsl:for-each>
</tr>
<xsl:for-each select="Product sList/Product[1]/SpecList/Spec">
<xsl:variable name="spec" select="SpecLab el"></xsl:variable>
<tr>
<td>
<xsl:value-of select="SpecLab el"/>
</td>
<xsl:for-each select="/ProductsList/Product/SpecList/Spec[SpecLabel =
$spec]">
<td>
<xsl:value-of select="SpecVal ue"/>
</td>
</xsl:for-each>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>

</xsl:stylesheet>

Jun 6 '07 #2
On Jun 6, 5:50 pm, Luc Alquier <LucAlqu...@dis cussions.micros oft.com>
wrote:
here it is

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

<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
<html>

<body>
<!--
This is an XSLT template file. Fill in this area with the
XSL elements which will transform your XML to XHTML.
-->
<table>
<tr>
<th>Label</th>
<xsl:for-each select="Product sList/Product">
<th>
<xsl:value-of select="concat( 'Product',@id)"/>
</th>
</xsl:for-each>
</tr>
<xsl:for-each select="Product sList/Product[1]/SpecList/Spec">
<xsl:variable name="spec" select="SpecLab el"></xsl:variable>
<tr>
<td>
<xsl:value-of select="SpecLab el"/>
</td>
<xsl:for-each select="/ProductsList/Product/SpecList/Spec[SpecLabel =
$spec]">
<td>
<xsl:value-of select="SpecVal ue"/>
</td>
</xsl:for-each>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>

</xsl:stylesheet>
I posted an earlier reply to the same problem in another group. You
may want to compare. I'm not a great advocate of intensive use of
xsl:for-each

<xsl:template match="ProducsL ist">
<table>
<tr>
<th>Label</th>
<xsl:apply-templates select="Product " mode="header"/>
</tr>
<xsl:apply-templates select="/ProducsList/Product/
SpecList/
Spec/SpecLabel[

not(

text()

=

ancestor::Produ ct/preceding-sibling::Produc t//SpecLabel/text()
)

]"/

</table>
</xsl:template>

<xsl:template match="Product" mode="header">
<th>
<xsl:text>Produ ct </xsl:text>
<xsl:value-of select="@id"/>
</th>
</xsl:template>

<xsl:template match="SpecLabe l">
<xsl:variable name="text" select="text()"/>
<tr>
<th>
<xsl:value-of select="$text"/>
</th>
<xsl:apply-templates select="/ProducsList/Product">
<xsl:with-param name="label" select="$text"/>
</xsl:apply-templates>
</tr>
</xsl:template>

<xsl:template match="Product" >
<xsl:param name="label"/>
<td>
<xsl:value-of select="SpecLis t/Spec[SpecLabel =
$label]/SpecValue"/>
</td>
</xsl:template>

outputs

<table>
<tr>
<th>Label</th><th>Product 1</th><th>Product 2</th><th>Product 3</th>
</tr>
<tr>
<th>Height</th><td>10</td><td>8</td><td>5</td>
</tr>
<tr>
<th>Width</th><td>6</td><td>5</td><td>2</td>
</tr>
<tr>
<th>Weight</th><td>20.5</td><td>18</td><td>10</td>
</tr>
</table>

Jun 6 '07 #3


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

<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
<html>

<body>
<!--
This is an XSLT template file. Fill in this area with the
XSL elements which will transform your XML to XHTML.
-->
<table>
<tr>
<th>Label</th>
<xsl:for-each select="Product sList/Product">
<th>
<xsl:value-of select="concat( 'Product',@id)"/>
</th>
</xsl:for-each>
</tr>
<xsl:for-each select="Product sList/Product[1]/SpecList/Spec">
<xsl:variable name="spec" select="SpecLab el"></xsl:variable>
<tr>
<td>
<xsl:value-of select="SpecLab el"/>
</td>
<xsl:for-each select="/ProductsList/Product/SpecList/Spec[SpecLabel =
$spec]">
<td>
<xsl:value-of select="SpecVal ue"/>
</td>
</xsl:for-each>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>

</xsl:stylesheet>

Jun 7 '07 #4
<PRE>
<?xml version="1.0" encoding="utf-8"?>

<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
<html>

<body>
<!--
This is an XSLT template file. Fill in this area with the
XSL elements which will transform your XML to XHTML.
-->
<table>
<tr>
<th>Label</th>
<xsl:for-each select="Product sList/Product">
<th>
<xsl:value-of select="concat( 'Product',@id)"/>
</th>
</xsl:for-each>
</tr>
<xsl:for-each select="Product sList/Product[1]/SpecList/Spec">
<xsl:variable name="spec" select="SpecLab el"></xsl:variable>
<tr>
<td>
<xsl:value-of select="SpecLab el"/>
</td>
<xsl:for-each select="/ProductsList/Product/SpecList/Spec[SpecLabel =
$spec]">
<td>
<xsl:value-of select="SpecVal ue"/>
</td>
</xsl:for-each>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>

</xsl:stylesheet>

</PRE>
Jun 7 '07 #5
Lee
On Jun 7, 1:18 am, Luc Alquier <LucAlqu...@dis cussions.micros oft.com>
wrote:
<PRE>
<?xml version="1.0" encoding="utf-8"?>

<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
<html>

<body>
<!--
This is an XSLT template file. Fill in this area with the
XSL elements which will transform your XML to XHTML.
-->
<table>
<tr>
<th>Label</th>
<xsl:for-each select="Product sList/Product">
<th>
<xsl:value-of select="concat( 'Product',@id)"/>
</th>
</xsl:for-each>
</tr>
<xsl:for-each select="Product sList/Product[1]/SpecList/Spec">
<xsl:variable name="spec" select="SpecLab el"></xsl:variable>
<tr>
<td>
<xsl:value-of select="SpecLab el"/>
</td>
<xsl:for-each select="/ProductsList/Product/SpecList/Spec[SpecLabel =
$spec]">
<td>
<xsl:value-of select="SpecVal ue"/>
</td>
</xsl:for-each>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>

</xsl:stylesheet>

</PRE>
guys, thank you very much, all solutions work, I learned a lot from
you guys. Thanks.

Jun 7 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1500
by: kevin bailey | last post by:
hi there, after having read a couple of books on XML and tons from the web i have an understanding of XML and also XSL. however - i need help at a basic level... we have a table in a DB - i need to be able to create an XHTML form to be able to add a new record to the table. this will obviously be shown in a browser.
1
1786
by: Scott | last post by:
The following is the XML I have to work with. Below is the question <Table0> <CaseID>102114</CaseID> <CaseNumber>1</CaseNumber> <DateOpened>2005-06-14T07:26:00.0000000-05:00</DateOpened> <OnCallPerson /> <CallType>Exposure</CallType> <ExposureReason>General</ExposureReason> <OtherExposureReason>Unintentional</OtherExposureReason> <ClientName>Test Client</ClientName>
2
1293
by: gene.ellis | last post by:
Hello everyone. I have a pretty straight forward question: I have some data stored in an XMl document in the format of: <comment_info> <comments>These are the comments</comments> <comment_heading>This is comment heading</comment_heading> </comment_info> <comment_info>
4
1318
by: RJN | last post by:
Hi Pardon me for posting an XML question here. Can XSLT be applied for transforming .txt files or are they applicable only for xml to xml transformation. Currently all the clients send file to a server in one particular format. The format of the file which the server accepts is going to change. So we need to build an intermediate system which will do the transformation from the old format to the new format. Can I use XSLT for
5
1620
by: Adam Sandler | last post by:
Hello, Before I begin, here's some background to the problem. I'm working on a web app which deals with maps. Via a browser, the users can zoom in, zoom out, and pan around a map of their geographic region. The users can also click a button called "identify". When they do this the mouse pointer changes to a crosshair and when they click on the map, the polygon under the cursor is captured and passed in a query to the database......
2
3122
by: Mad Scientist Jr | last post by:
>From an asp.net web page I want the user to open the results of a SQL query in Excel, as automatically as possible (ie not having to loop through columns, rows, in code). For this, dataset.writexml works great (got the code from http://forums.devx.com/archive/index.php/t-57273.html ) The only question I have is, when Excel opens up, it isn't the view I would prefer. It opens as a read-only workbook, I would prefer as an
2
1692
by: Adam dR. | last post by:
I have an xml file similar to: <menu> <menuitem name="home" show="false"/> <menuitem name="about" show="true"/> <menuitem name="links" show="true"/> <menuitem name="games" show="true"/> <menuitem name="learn" show="true"/> <menuitem name="order" show="true"/> <menuitem name="contact" show="true"/> <menuitem name="support" show="false"/>
14
5152
by: Lee | last post by:
I have a xml file, here is sample part: <?xml version="1.0" encoding="UTF-8"?> <ProducsList> <Product id="1"> <SpecList> <Spec> <SpecLabel>Height</SpecLabel> <SpecValue>10</SpecValue> <SpecCat>Dimension</SpecCat> </Spec>
2
4363
by: djnokturnal | last post by:
Hey guys / gals, First time posting and of course I am sure it is something that has been answered 100 times but for some reason I just cant find the answer :) First off here is the structure of the xml: <Stats> <Structure> <Column DisplayName="GP" FieldName="GamesPlayed" Priority="1" /> <Column DisplayName="G" FieldName="Goals" Priority="2" />
0
8689
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9273
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9136
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9030
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6605
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5933
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4439
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4703
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2081
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.