473,785 Members | 2,831 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_E10E1E1A 1" V="25_1_1" />
<A C="P_E10E1E1A 1" 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_E11E1E1A 1" V="25_1_1" />
<A C="P_E11E1E1A 1" 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:styleshe et 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-->
<IsNewPlusParen t>

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

</IsNewPlusParent >

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

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

<!-- 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>
<IsNewPlusParen t>
<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_E10E1E1A 1" V="25_1_1" />
<A C="P_E10E1E1A 1" 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_E11E1E1A 1" V="25_1_1" />
<A C="P_E11E1E1A 1" 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 1526
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.goog legroups.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_E10E1E1A 1" V="25_1_1" />
<A C="P_E10E1E1A 1" 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_E11E1E1A 1" V="25_1_1" />
<A C="P_E11E1E1A 1" 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:styleshe et 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-->
<IsNewPlusParen t>

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

</IsNewPlusParent >

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

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

<!-- 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>
<IsNewPlusParen t>
<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_E10E1E1A 1" V="25_1_1" />
<A C="P_E10E1E1A 1" 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_E11E1E1A 1" V="25_1_1" />
<A C="P_E11E1E1A 1" 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
3610
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 instruction document (not data based) - same as using an xml web control. The resulting html is on the client? but what about the server side of things? Trying to figure out how to change and save the xmlDocument. It I put a button OUTSIDE of the...
1
3576
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 { private const String filename = "mydata.xml"; private const String stylesheet = "myStyleSheet.xsl";
6
1730
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 XSLT file that does not work correctly is: <Token TokenId="3129"> <xsl:for-each select="EDI/Segment/Element"> <Value Segment="PRF" Position="1"> <xsl:attribute name="SegmentIndex"> <xsl:value-of select="../@SegmentIndex"/></xsl:attribute>
1
2688
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 <?xml version="1.0" encoding="windows-1255" ?><xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:utils="urn:galileo-com:msxsl-jscript-utilities" version="1.0"><xsl:template...
3
1834
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 = doc.CreateNavigator(); XslTransform xslTran = new XslTransform(); xslTran.Load("Transform.XSL"); xslTran.Transform(nav, null, Response.Output, null); This produces me a nice HTML page with enhanced formatting specified
3
2255
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 (white space cannot be striped) XmlDocument DealXmlDocument = new XmlDocument(); DealXmlDocument.LoadXml(DataCalls);
4
8531
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 image. The transform will take a rectangular 2D image and transform it to a 3D representation in 2D. Please see the link to see what I am trying to do: http://seanberry.com/transform.png I have PIL v1.15 installed which has a PERSPECTIVE...
1
1385
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 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'>
1
1053
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 400 6 /4 /2006 gg 3
0
9480
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
10324
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
10147
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
10090
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
7499
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
6739
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
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2879
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.