473,472 Members | 2,184 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Extend XML file attributes using XSLT

Hi folks!

I have a little noob problem here with XSLT. I have a XML file that
looks like this:

<archiveFiles>
<module path="c:/temp/module_m17_blabla.tmp"/>
<module path="c:/temp/module_m34_blabla.tmp"/>
...
<moduleAddition path="c:/temp/moduleaddition_m17.tmp"/>
...
</archiveFiles>

What I want to do now is the following:

1.) Copy name part of filename in <module>
---------------------------------------------
I want to copy that module name part and add it to a new attribute
called "name". How should I do this? The name of each module comes
right after module_ in the path-attributes.

2.) Reference additional information to these modules
---------------------------------------------
Finally another attribute "addition" should be added to each <module>
when there is a <moduleAdditionnode with the same module name in its
"path" attribute. So that the outcome of the upper XML file looks like
this:

<archiveFiles>
<module name ="m17" path="c:/temp/module_m17_blabla.tmp"
additon="c:/temp/moduleaddition_m17.tmp"/>
<module name ="m34" path="c:/temp/module_m34_blabla.tmp"/>
...
</archiveFiles>

I really hope you can help me. I never worked with XSLT before and I
couldn't find the right hints and/or tutorials yet. :(

Thanks a lot in advance!

/Chris

Nov 9 '07 #1
3 3326
What the hell makes you react like I just came through your door and
started dissing you? I didn't make any harm, did I? You wanted a valid
source file... Well, it is valid! And I don't give out any business
secrets by posting it. Maybe I just can't express myself in English,
but... I wish I could understand your reaction. We "know" each other
since three or four posts and all of a sudden you patronize me. I
wouldn't do that with a noob that politely asked a question!

I guess I won't get help here any longer thanks to this lame fight...

I surely understand your hints, but if you once checked out my profile
you'd see that I don't have too much experience to make it right for
everybody in a Usenet newsgroup! I just don't know it better and your
reaction makes me guess that this is more relevant to you than the
fact that I am willing to learn! It not that I ignore your words only
waiting for the solution of my problem... Aw, whatever!
Nov 23 '07 #2
OK, break. I guess I'm getting closer now...

There's still one problem: By now I just get the top-level-nodes
attributes by using something like this: <xsl:value-of
select="$archiveDoc//Product/@moduleName"/>
How do I get the right nodes attribute here? I have to retrieve the
right node's attribute depending on the cid-attribute. But how do I
put that into the pattern "$archiveDoc//Product/@moduleName"? Or si
there another way doing this? Maybe with a <xsl:whenpart or
something like that?

Here's my entry-template (the other ones look similar):

<xsl:template name="component" match="/">
<xsl:for-each select="$treeDoc//Component">
<Component topLevelModule="{@topLevelModule}"
description="{@description}" cid="{@cid}">
<xsl:if test="@cid = $archiveDoc//Product/@cid">
<xsl:attribute name="moduleName"><xsl:value-of
select="$archiveDoc//Product/@moduleName"/></xsl:attribute>
<xsl:attribute name="subsystem"><xsl:value-of
select="$archiveDoc//Product/@subsystem"/></xsl:attribute>
<xsl:attribute name="tokens"><xsl:value-of select="$archiveDoc//
Product/@tokens"/></xsl:attribute>
<xsl:attribute name="path"><xsl:value-of select="$archiveDoc//
Product/@path"/></xsl:attribute>
<xsl:attribute name="tc"><xsl:value-of select="$archiveDoc//
Product/@tc"/></xsl:attribute>
</xsl:if>
<xsl:if test="SubComponent">
<xsl:call-template name="sub-component"/>
</xsl:if>
</Component>
</xsl:for-each>
</xsl:template>
Nov 26 '07 #3
On 26 Nov., 14:52, "Christian Rühl" <ch...@cruehl.comwrote:
OK, break. I guess I'm getting closer now...

There's still one problem: By now I just get the top-level-nodes
attributes by using something like this: <xsl:value-of
select="$archiveDoc//Product/@moduleName"/>
How do I get the right nodes attribute here? I have to retrieve the
right node's attribute depending on the cid-attribute. But how do I
put that into the pattern "$archiveDoc//Product/@moduleName"? Or si
there another way doing this? Maybe with a <xsl:whenpart or
something like that?

Here's my entry-template (the other ones look similar):

<xsl:template name="component" match="/">
<xsl:for-each select="$treeDoc//Component">
<Component topLevelModule="{@topLevelModule}"
description="{@description}" cid="{@cid}">
<xsl:if test="@cid = $archiveDoc//Product/@cid">
<xsl:attribute name="moduleName"><xsl:value-of
select="$archiveDoc//Product/@moduleName"/></xsl:attribute>
<xsl:attribute name="subsystem"><xsl:value-of
select="$archiveDoc//Product/@subsystem"/></xsl:attribute>
<xsl:attribute name="tokens"><xsl:value-of select="$archiveDoc//
Product/@tokens"/></xsl:attribute>
<xsl:attribute name="path"><xsl:value-of select="$archiveDoc//
Product/@path"/></xsl:attribute>
<xsl:attribute name="tc"><xsl:value-of select="$archiveDoc//
Product/@tc"/></xsl:attribute>
</xsl:if>
<xsl:if test="SubComponent">
<xsl:call-template name="sub-component"/>
</xsl:if>
</Component>
</xsl:for-each>
</xsl:template>
Solution found: <xsl:attribute name="moduleName"><xsl:value-of
select="$archiveDoc//Product[attribute::cid=$compID]/@moduleName"/></
xsl:attribute>

Thank you and sorry for taxing your patience.
Nov 26 '07 #4

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

Similar topics

2
by: Wolfgang | last post by:
I'm applying a simple XSLT style sheet to an XML file. The style sheet is: http://piru.alexandria.ucsb.edu/~rnott/MetadataMapping/access-report.xsl The XML file is here: ...
1
by: Eric Anderson | last post by:
I am trying to use XSLT to extend XHTML so that I can have custom widgets. For example I have a calendar control. Whenever I put the following in the psudo-XHTML doc: <calendarbox name="mycal"/>...
9
by: Soren Kuula | last post by:
Hi, I just can't find namespaces of attributes stated clearly enough in the XML namespace spec. But .. I hear rumors that attributes, unless qualified otherwise, default to the namespace of the...
3
by: Stephan Brunner | last post by:
Hi I have created two flavors of an XSLT stylesheet to transform all attributes of an XML document to elements: They both work as expected with MSXML and XMLSPY but throw an exception ...
2
by: Robert | last post by:
I have the XML file which has a structure similar to one I pasted at the end of this post. As you can see many elements are using different id attributes. For example element Window uses WinID...
7
by: Cerebrus99 | last post by:
Hi all, I am confused about how to sort an XML file. I mean how to *actually* sort the data in the physical file, not how to display sorted data. I am using a large XML file as a back-end...
2
by: jkflens | last post by:
Hello, i convert one XML-document by using XSLT into another XML-document. First change all attributes to elements is no problem. Then i try to insert a new element into the new document by...
3
by: R. P. | last post by:
Subject: XSLT to transform a flat XML file into a structured text file I have an XML file that lists the PDF file segment names and titles of a larger document and looks something like this: ...
5
by: mahesh.nimbalkar | last post by:
When I transform XML, XSLT automatically adds extra attributes to the node which are declared in DTD (default DTD attributes) . I just want XSLT not to add these extra default attributes from DTD....
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
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
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...
1
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,...
1
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...
0
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...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.