473,406 Members | 2,343 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Matching attribute names to element names in a different path

I want to create a generic xslt that would take xml input like:

################################################## ########################
<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/xsl" href="lookup.xslt"?>
<root>
<Schema name="Schema1" xmlns="urn:schemas-microsoft-com:xml-data"
xmlns:dt="urn:schemas-microsoft-com:datatypes">
<ElementType name="lookup" content="empty" model="closed">
<AttributeType name="col1" dt:type="i2"/>
<AttributeType name="col2" dt:type="i2"/>
<AttributeType name="col3" dt:type="i2"/>
<AttributeType name="col4 dt:type="i2"/>
<AttributeType name="col5 dt:type="i2"/>
<attribute type="col1"/>
<attribute type="col2"/>
<attribute type="col3"/>
<attribute type="col4/>
<attribute type="col5>
</ElementType>
</Schema>
<lookup xmlns="x-schema:#Schema1" col1="a" col2="b" col3="c"/>
<lookup xmlns="x-schema:#Schema1" col1="d" col3="e" />
</root>
################################################## ########################

and turn it into a table with col1, col2, col3, col4 and col5 as
headings
and with the data it will put "a" in col1, "b" in col2 etc.

The problem is that, because column 4 has no data in the elements,
that column is not generated in the table.

So I am using the Schema to generate the column headings, but now I
have to match the data to the correct columns... I can onnly do that
by matching the attribute names to the corresponding element name in
the schema declaration. But I don't know how to do this...

Here is my attempt. Any help would be greatly appreciated. Thanks in
advance.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:data="x-schema:#Schema1"
xmlns:schema="urn:schemas-microsoft-com:xml-data">
<xsl:template match="/root">
<TABLE>
<xsl:apply-templates select="schema:Schema" /> <!-- headings -->
<xsl:apply-templates select="data:lookup" /> <!-- data -->
</TABLE>
</xsl:template>

<xsl:template match="schema:Schema">
<tr style="color:White;background-color:Blue;">
<td></td>
<xsl:for-each select="*/*"><!-- Select all the elements of the
schema-->
<xsl:if test="name(.)='AttributeType' and position() != 1"><!--
only pick the AttributeType elements, otherwise you will have the
columns twice -->
<xsl:for-each select="@name">
<td>
<xsl:attribute name="name"><xsl:value-of
select="name()"/></xsl:attribute>
<xsl:value-of select="."/>
</td>
</xsl:for-each>
</xsl:if>
</xsl:for-each>
<td></td>
</tr>
</xsl:template>

<!-- lookup Template -->
<xsl:template match="data:lookup">
<tr>
<td></td>
<xsl:for-each select="@*">
<td>
<xsl:value-of select="." />
</td>
</xsl:for-each>
<td></td>
</tr>
</xsl:template>
</xsl:stylesheet>
Jul 20 '05 #1
0 1397

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

Similar topics

7
by: svilen | last post by:
hello again. i'm now into using python instead of another language(s) for describing structures of data, including names, structure, type-checks, conversions, value-validations, metadata etc....
2
by: ahogue at theory dot lcs dot mit dot edu | last post by:
Hello - Is there any way to match complex subtree patterns with XPath? The functions I see all seem to match along a single path from root to leaf. I would like to match full subtrees. For...
8
by: Hugh Sparks | last post by:
When processing an xml document that contains elements such as: <element xmlns="goop"/> ... <element xmlns="gleep"/> I want to create two xsl stylesheet templates: one that matches the...
2
by: mid | last post by:
Hello! First please understand tha my xml knowledge is very very short. I'm new at xml world. I need to understand how do I map a given sqlColumn to a xml element or attribute. I was given...
4
by: Karine Bosch | last post by:
Hi, My xml document uses different namespaces: <x:root xmlns:x="x:ns:meta/"> <element1 xmlns:adam="http://ns.alfaprint.be/"> </root> This gives problems when using an XPath query. I...
9
by: Philipp | last post by:
Hello. OK I know this is the most asked question in XML (it says in some tutorial), but still. Please give me your insight on this (as I'm a newbie). I want to store parameters for a programm in...
2
by: gary.goodwin | last post by:
HI I am trying to understand Attribute usage. For example the class SerializableAttribute is a class correct? So why when it is actually u sed the "Attribute" portion of the name is dropped. The...
4
by: J | last post by:
Hello Group- I have limited programming experience, but I'm looking for a generic way to search through a root directory for subdirectories with similar names, organize and group them by...
2
by: Arndt Jonasson | last post by:
This is a modelling style question, I think. I am working with a somewhat XML Schema-like formalism which defines the structure of an instance document, supplying a number of built-in types (a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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...

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.