473,406 Members | 2,713 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.

XSL Transform Help, Please

I am having a problem with writing an XSL Transform. Please help.

Note: I know this a long post but I wanted to provide as must detail as
possible. Any help would be appreciated. (Just started writing my
first transform yesterday and no one at my company knows this stuff.)

Assume I have the following XML:

<P C="P" O="1" >
<E C="P_E1" O="1" W='True'>
<A C="P_E1A1" V="1" />
<A C="P_E1A1" V="2" />
</E>
<E C="P_E10" O="13" W='True'>
<A C="P_E10A1" V="25" />
<A C="P_E10A1" V="26" />
<E C="P_E10E1" O="13_1" W='True'>
<A C="P_E10E1A1" V="25_1" />
<A C="P_E10E1A1" V="26_1" />
<E C="P_E10E1E1" O="13_1_1" W='True'>
<A C="P_E10E1E1A1" V="25_1_1" />
<A C="P_E10E1E1A1" V="26_1_1" />
</E>
</E>
</E>
<E C="P_E11" O="13" >
<A C="P_E11A1" V="25" />
<A C="P_E11A1" V="26" />
<E C="P_E11E1" O="13_1" W='True'>
<A C="P_E11E1A1" V="25_1" />
<A C="P_E11E1A1" V="26_1" />
<E C="P_E11E1E1" O="13_1_1" W='True'>
<A C="P_E11E1E1A1" V="25_1_1" />
<A C="P_E11E1E1A1" V="26_1_1" />
</E>
</E>
</E>
<E C="P_E12" O="14" >
<A C="P_E12A1" V="27" />
<E C="P_E12E1" O="15" W='True'>
<A C="P_E12E1A1" V="27_1" />
</E>
</E>
</P>

High-level Requirements:
Basically, I need to get all of the nodes where the attribute
W='True". These nodes need to be grouped together with the parent
element tag, plus attributes, that does not have a W attribute.

More Detail:
I need to merge this information into an existing system.
The W="True" indicates that the Entity (E) is a new element.
If an Entity (E) has an attribute of W="True" all child Entities
(E) will also have a W="True". (If the parent is new, all children,
grandchildren and etc are new as well.)
I need the parent element to reference the exiting item to merge in all
of the new Entities.

Here is what I have so far:

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="UTF-8" />
<xsl:template match="/">
<root>
<!-- Get IsNew Entities Plus Parent-->
<IsNewPlusParent>

<!-- Get all entities which are new plus thier parents -->
<xsl:apply-templates select="//P [E[@W='True']] | //E
[E[@W='True']]" mode="IsNewPlusParent"/>

</IsNewPlusParent>

</root>
</xsl:template>
<!-- IsNew Plus Parent Template(s) - Start-->

<xsl:template match="P|E" mode="IsNewPlusParent">

<!-- Print P or E (parent of new entities element-->
<xsl:element name="{local-name()}">

<!-- Add all attributes to the element-->
<xsl:for-each select="@*">
<xsl:copy-of select="."/>
</xsl:for-each>

<!-- Add all E nodes that are new-->
<xsl:for-each select="child::E [@W='True']">
<xsl:copy-of select="."/>
</xsl:for-each>

</xsl:element>
</xsl:template>

<!-- IsNew Plus Parent Template(s) - End-->
</xsl:stylesheet>

The problem with the above code is that it processes not only the
existing parent but all of parents.

Here is the output I would like:
<root>
<IsNewPlusParent>
<P C="P" O="1">
<E C="P_E1" O="1" W="True">
<A C="P_E1A1" V="1" />
<A C="P_E1A1" V="2" />
</E>
<E C="P_E10" O="13" W="True">
<A C="P_E10A1" V="25" />
<A C="P_E10A1" V="26" />
<E C="P_E10E1" O="13_1" W="True">
<A C="P_E10E1A1" V="25_1" />
<A C="P_E10E1A1" V="26_1" />
<E C="P_E10E1E1" O="13_1_1" W="True">
<A C="P_E10E1E1A1" V="25_1_1" />
<A C="P_E10E1E1A1" V="26_1_1" />
</E>
</E>
</E>
</P>
<E C="P_E11" O="13">
<E C="P_E11E1" O="13_1" W="True">
<A C="P_E11E1A1" V="25_1" />
<A C="P_E11E1A1" V="26_1" />
<E C="P_E11E1E1" O="13_1_1" W="True">
<A C="P_E11E1E1A1" V="25_1_1" />
<A C="P_E11E1E1A1" V="26_1_1" />
</E>
</E>
</E>
<E C="P_E12" O="14">
<E C="P_E12E1" O="15" W="True">
<A C="P_E12E1A1" V="27_1" />
</E>
</E>
</IsNewPlusParent>
</root>

Again, thank you reading this. Any help would be appreciated.

Dec 8 '06 #1
1 1505
Candle i think what you def need is grouping
see these samples here at :-
http://www.xmlpitstop.com/StyleSheetCentral/SSC_GR.aspx
You can make use of the Xsl:Key element
Hope that helps
Patrick
"Candle" <AB*****@gmail.comwrote in message
news:11**********************@f1g2000cwa.googlegro ups.com...
I am having a problem with writing an XSL Transform. Please help.

Note: I know this a long post but I wanted to provide as must detail as
possible. Any help would be appreciated. (Just started writing my
first transform yesterday and no one at my company knows this stuff.)

Assume I have the following XML:

<P C="P" O="1" >
<E C="P_E1" O="1" W='True'>
<A C="P_E1A1" V="1" />
<A C="P_E1A1" V="2" />
</E>
<E C="P_E10" O="13" W='True'>
<A C="P_E10A1" V="25" />
<A C="P_E10A1" V="26" />
<E C="P_E10E1" O="13_1" W='True'>
<A C="P_E10E1A1" V="25_1" />
<A C="P_E10E1A1" V="26_1" />
<E C="P_E10E1E1" O="13_1_1" W='True'>
<A C="P_E10E1E1A1" V="25_1_1" />
<A C="P_E10E1E1A1" V="26_1_1" />
</E>
</E>
</E>
<E C="P_E11" O="13" >
<A C="P_E11A1" V="25" />
<A C="P_E11A1" V="26" />
<E C="P_E11E1" O="13_1" W='True'>
<A C="P_E11E1A1" V="25_1" />
<A C="P_E11E1A1" V="26_1" />
<E C="P_E11E1E1" O="13_1_1" W='True'>
<A C="P_E11E1E1A1" V="25_1_1" />
<A C="P_E11E1E1A1" V="26_1_1" />
</E>
</E>
</E>
<E C="P_E12" O="14" >
<A C="P_E12A1" V="27" />
<E C="P_E12E1" O="15" W='True'>
<A C="P_E12E1A1" V="27_1" />
</E>
</E>
</P>

High-level Requirements:
Basically, I need to get all of the nodes where the attribute
W='True". These nodes need to be grouped together with the parent
element tag, plus attributes, that does not have a W attribute.

More Detail:
I need to merge this information into an existing system.
The W="True" indicates that the Entity (E) is a new element.
If an Entity (E) has an attribute of W="True" all child Entities
(E) will also have a W="True". (If the parent is new, all children,
grandchildren and etc are new as well.)
I need the parent element to reference the exiting item to merge in all
of the new Entities.

Here is what I have so far:

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="UTF-8" />
<xsl:template match="/">
<root>
<!-- Get IsNew Entities Plus Parent-->
<IsNewPlusParent>

<!-- Get all entities which are new plus thier parents -->
<xsl:apply-templates select="//P [E[@W='True']] | //E
[E[@W='True']]" mode="IsNewPlusParent"/>

</IsNewPlusParent>

</root>
</xsl:template>
<!-- IsNew Plus Parent Template(s) - Start-->

<xsl:template match="P|E" mode="IsNewPlusParent">

<!-- Print P or E (parent of new entities element-->
<xsl:element name="{local-name()}">

<!-- Add all attributes to the element-->
<xsl:for-each select="@*">
<xsl:copy-of select="."/>
</xsl:for-each>

<!-- Add all E nodes that are new-->
<xsl:for-each select="child::E [@W='True']">
<xsl:copy-of select="."/>
</xsl:for-each>

</xsl:element>
</xsl:template>

<!-- IsNew Plus Parent Template(s) - End-->
</xsl:stylesheet>

The problem with the above code is that it processes not only the
existing parent but all of parents.

Here is the output I would like:
<root>
<IsNewPlusParent>
<P C="P" O="1">
<E C="P_E1" O="1" W="True">
<A C="P_E1A1" V="1" />
<A C="P_E1A1" V="2" />
</E>
<E C="P_E10" O="13" W="True">
<A C="P_E10A1" V="25" />
<A C="P_E10A1" V="26" />
<E C="P_E10E1" O="13_1" W="True">
<A C="P_E10E1A1" V="25_1" />
<A C="P_E10E1A1" V="26_1" />
<E C="P_E10E1E1" O="13_1_1" W="True">
<A C="P_E10E1E1A1" V="25_1_1" />
<A C="P_E10E1E1A1" V="26_1_1" />
</E>
</E>
</E>
</P>
<E C="P_E11" O="13">
<E C="P_E11E1" O="13_1" W="True">
<A C="P_E11E1A1" V="25_1" />
<A C="P_E11E1A1" V="26_1" />
<E C="P_E11E1E1" O="13_1_1" W="True">
<A C="P_E11E1E1A1" V="25_1_1" />
<A C="P_E11E1E1A1" V="26_1_1" />
</E>
</E>
</E>
<E C="P_E12" O="14">
<E C="P_E12E1" O="15" W="True">
<A C="P_E12E1A1" V="27_1" />
</E>
</E>
</IsNewPlusParent>
</root>

Again, thank you reading this. Any help would be appreciated.

Dec 14 '06 #2

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

Similar topics

5
by: KathyB | last post by:
If someone could just explain this to me...I just don't get it! I have an aspx page where I retrieve several session variables and use xmlDocument to transform xml file with xsl file into an...
1
by: Owen | last post by:
Hello: I have some xml and xsl in string, "not in file". I want to transform the xml with xsl and the result I want in string (but in xml format). I read this sample : public class Sample {...
6
by: tcdevelopment | last post by:
I have a XSLT file that gives expected results when I transform using MSXML V4.0 in a simple vbs file. However when using XslTransform in dotnet, I do not get the same results. The part of the...
1
by: Danny Lesnik | last post by:
Hi i have my XML file c:\prd.xm <?xml-stylesheet type="text/xsl" href="prd.xsl"?><products><product><a>2</a><b>3</b></product><product><a>4</a><b>2</b></product></products This is my XSL file...
3
by: vitaly.tomilov | last post by:
I'm using an ASP.NET form to display data from my database table, and I'm doing it in the following way: XmlDataDocument doc = new XmlDataDocument(mydataSet); XPathNavigator nav =...
3
by: BrianDH | last post by:
Hi I am having a problem doing the tranform. Unlike all the examples I have found, I do not load my XML document via a path but from a datacall. I get erros when I try to do the transform...
4
by: Dean Card | last post by:
Okay, so here is the situation. I have need to do some on-the-fly image creation. I have everything working great except for the last part of it, applying a perspective type transform to the...
1
by: Candle | last post by:
I am having a problem with writing an XSL Transform. Please help. Note: I know this a long post but I wanted to provide as must detail as possible. Any help would be appreciated. (Just started...
1
by: december03 | last post by:
I need to transform data from the access main and sub table for analysis Main table ID Seiz_Date Seiz_DateTx Seiz_DateYr 400 5 /1 /2006 aa 8 400 5 /2 /2006 vv 7 400 5 /13/2006 cc 5 ...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
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.