XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Mark MaltbySubject: Finding a node by its name!
Author: Mark Maltby
Date: 08 Jun 2006 03:55 AM
Originally Posted: 08 Jun 2006 03:56 AM
I need to create a dynamic table based on fields required by the user. I have one piece of xml which describes my table. So in this xml is a list of the column headers I need. I populate the table headers from this. I then have another piece of xml which contains the contents for this table. I need to match up the column headers from the first xml with the node names in the other xml and then extract the xml from the matching node.

Is it possible to read the node name instead of its contents to do this test?

Hope this makes sense.

Thanks

Postnext
Minollo I.Subject: Finding a node by its name!
Author: Minollo I.
Date: 08 Jun 2006 09:47 AM
Mark,
I kind of guess what you are describing; but a concrete example would make it easier to understand and a solution easier to suggest.

Minollo

Postnext
Mark MaltbySubject: Finding a node by its name!
Author: Mark Maltby
Date: 08 Jun 2006 10:02 AM
<?xml version="1.0"?>
<MyTables>
<MyTable name="MyTable">
<columns amount="5">
<column>
<name>ID</name>
</column>
<column>
<name>Title</name>
</column>
<column>
<name>Score</name>
</column>
<column>
<name>Owner</name>
</column>
<column>
<name>Status</name>
</column>
</columns>
<rows amount="1">
<row></row>
<row></row>
<row></row>
<row></row>
<row></row>
</rows>


</MyTable>
</MyTables>

SECOND XML
<?xml version="1.0"?>
<Items>
<Item>
<ID>value</ID>
<Title>Value</Title>
<Score>Value</Score>
<Owner>value</Owner>
<status>value</Status>
</Item>
<Item>
<ID>value</ID>
<Title>Value</Title>
<Score>Value</Score>
<Owner>value</Owner>
<status>value</Status>
</Item>
<Item>
<ID>value</ID>
<Title>Value</Title>
<Score>Value</Score>
<Owner>value</Owner>
<status>value</Status>
</Item>
</Items

So i need to do a match up with ID as a value in the first bit of the xml and the ID as a node name in the second bit of xml


UnknownNoname(20).

Postnext
Minollo I.Subject: Finding a node by its name!
Author: Minollo I.
Date: 08 Jun 2006 11:04 AM
This should work ok if you use the Stylus Studio built-in processor or Saxon 8.x; with other processors you'll need to use proprietary extensions to handle $colNames as a node set.

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>

<xsl:template match="/">
<xsl:variable name="colNames">
<xsl:for-each select="document('c:\column-info.xml')//column">
<xsl:copy-of select="."/>
</xsl:for-each>
</xsl:variable>
<table>
<tr>
<xsl:for-each select="$colNames/column">
<td><xsl:value-of select="name"/></td>
</xsl:for-each>
</tr>
<xsl:for-each select="document('c:\data.xml')//Item">
<xsl:variable name="item"><xsl:copy-of select="."/></xsl:variable>
<tr>
<xsl:for-each select="$colNames/column">
<xsl:variable name="colName" select="name"/>
<td>
<xsl:value-of select="$item/Item/*[local-name()=$colName]"/>
</td>
</xsl:for-each>
</tr>
</xsl:for-each>
</table>
</xsl:template>

</xsl:stylesheet>

Postnext
Mark MaltbySubject: Finding a node by its name!
Author: Mark Maltby
Date: 13 Jun 2006 06:14 AM
The code you provided work really well, but I am limited to using MSXML. Could you explain what and how to use proprietary extensions?

Thanks

Postnext
Minollo I.Subject: Finding a node by its name!
Author: Minollo I.
Date: 13 Jun 2006 09:07 AM
This is the MSXML compatible example:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt">
<xsl:output method="html"/>

<xsl:template match="/">
<xsl:variable name="colNames">
<xsl:for-each select="document('c:\column-info.xml')//column">
<xsl:copy-of select="."/>
</xsl:for-each>
</xsl:variable>
<table>
<tr>
<xsl:for-each select="msxsl:node-set($colNames)/column">
<td><xsl:value-of select="name"/></td>
</xsl:for-each>
</tr>
<xsl:for-each select="document('c:\data.xml')//Item">
<xsl:variable name="item"><xsl:copy-of select="."/></xsl:variable>
<tr>
<xsl:for-each select="msxsl:node-set($colNames)/column">
<xsl:variable name="colName" select="name"/>
<td>
<xsl:value-of select="msxsl:node-set($item)/Item/*[local-name()=$colName]"/>
</td>
</xsl:for-each>
</tr>
</xsl:for-each>
</table>
</xsl:template>

</xsl:stylesheet>

Postnext
Mark MaltbySubject: Finding a node by its name!
Author: Mark Maltby
Date: 13 Jun 2006 09:12 AM
what does the following mean

xmlns:msxsl="urn:schemas-microsoft-com:xslt

Would i have to connected to the web to use its functions?

Posttop
Minollo I.Subject: Finding a node by its name!
Author: Minollo I.
Date: 13 Jun 2006 09:39 AM
No; that's just a namespace declaration.

 
Topic Page 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.