473,387 Members | 1,440 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,387 software developers and data experts.

how to approach an XSLT task

This is my first XSLT project and I need some guidance on the approach
to take.

The problem is to take a document in one XML format and transform it
into another XML format. The source format is fixed but the
destination format will evolve. The two formats are completely
unrelated, so there are source elements we will ignore and destination
elements we will never receive.

However the management has decreed that we mustn't throw away any
data, since we may modify the destination format in such a way that we
can now accommodate source data that we couldn't previously. Therefore
the destination format contains a catch all area that is designed for
all *unprocessed* source data.

Perhaps an example will make this clear

<source>
<team>
<name>Arsenal</name>
<manager><name><first>Arsene</first><last>Wenger</last></name></manager>
<star-player><name><first>Thierry</first><last>Henri</last></name></star-player>
</team>
</source>

If we aren't interested in the star player this might be transformed
to say

<dest>
<team name="Arsenal">
<manager>Arsene Wenger</manager>
</team>
<unprocessed>
<team>
<star-player><name><first>Thierry</first><last>Henri</last></name></star-player>
</team>
</unprocessed>
</dest>

Notice how the processed portion has been transformed but the
unprocessed portion (including the team tag) has been dumped unchanged
into the unprocessed tag.

So any ideas on what approach can I take to code this in an elegant
and robust way? I want to do some sort of 'catch all' processing that
will automatically recognise which portions of the document are
unprocessed by the rest of my XSLT code.

MTIA
John
Jul 20 '05 #1
6 1398
On 22/01/2004, around 14:23, John Harrison wrote:

JH> Notice how the processed portion has been transformed but the
JH> unprocessed portion (including the team tag) has been dumped unchanged
JH> into the unprocessed tag.
This bit is at odds with everything else you've said; the <team>
element is processed but you want to include it in the <unprocessed>
area.

I think I understand why; you need so qualification of where the
unprocessed data came from. But if you follow that line a little
further what would you expect <unprocessed> to contain if, say you
decided you didn't want first names but did want to include the last
name of <star-player>? I'm guessing you'd want something like this...

<unprocessed>
<team>
<manager>
<last>Wenger</last>
</manager>
<star-player>
<last>Henri</last>
</star-player>
</team>
</unprocessed>

Now even that's ok until your data contains more than one team and you
end up with ...

<unprocessed>
<team>
<manager>
<last>Wenger</last>
</manager>
<star-player>
<last>Henri</last>
</star-player>
</team>
<team>
<manager>
<last>Keeganr</last>
</manager>
<star-player>
<last>Somebloke</last>
</star-player>
</team>
</unprocessed>

Similar, but different, problems occur if, say, a team has 2 'star
players'.

How do you know which bit of un processed data belongs to which
source?

I think that you need to think about tagging your elements with an ID
and using that ID to link the unprocessed data back to the relevant
bits of the destination data.

If any of the above is relevant to your problem, let me know and we
can look at ways around it.

--
Stuart
It's all fun and games 'til someone loses an eye! Then it's a SPORT!

Jul 20 '05 #2
On 22 Jan 2004 05:58:29 -0800, jh*******@cas.org (John Harrison)
wrote:
So any ideas on what approach can I take to code this in an elegant
and robust way


Namespaces. Just "don't throw any data away" by preserving the whole
damn lot. For each resource (player, team, whatever) then have a
property on it called "source" and use xsl:copy to make a simple copy
of the source resource.

It's bulky, but that's very rarely a real problem.

--
Die Gotterspammerung - Junkmail of the Gods
Jul 20 '05 #3
Andy Dingley <di*****@codesmiths.com> wrote in message news:<fq********************************@4ax.com>. ..
On 22 Jan 2004 05:58:29 -0800, jh*******@cas.org (John Harrison)
wrote:
So any ideas on what approach can I take to code this in an elegant
and robust way


Namespaces. Just "don't throw any data away" by preserving the whole
damn lot. For each resource (player, team, whatever) then have a
property on it called "source" and use xsl:copy to make a simple copy
of the source resource.

It's bulky, but that's very rarely a real problem.


That's certainly an option, and probably what we'll go for. I thought
I could do something smarter but it seems to be more difficult than I
appreciated.

I don't get the namespace angle however, could you explain that in a
bit more detail (and shouldn't it be xsl:copy-of not xsl:copy?).

John
Jul 20 '05 #4
DFN-CIS NetNews Service <sh******@estatecomputers.com> wrote in message news:<19***********************@estatecomputers.co m>...
On 22/01/2004, around 14:23, John Harrison wrote:

JH> Notice how the processed portion has been transformed but the
JH> unprocessed portion (including the team tag) has been dumped unchanged
JH> into the unprocessed tag.
This bit is at odds with everything else you've said; the <team>
element is processed but you want to include it in the <unprocessed>
area.

I think I understand why; you need so qualification of where the
unprocessed data came from.
Right.
But if you follow that line a little
further what would you expect <unprocessed> to contain if, say you
decided you didn't want first names but did want to include the last
name of <star-player>? I'm guessing you'd want something like this...

<unprocessed>
<team>
<manager>
<last>Wenger</last>
</manager>
<star-player>
<last>Henri</last>
</star-player>
</team>
</unprocessed>

Now even that's ok until your data contains more than one team and you
end up with ...

<unprocessed>
<team>
<manager>
<last>Wenger</last>
</manager>
<star-player>
<last>Henri</last>
</star-player>
</team>
<team>
<manager>
<last>Keeganr</last>
</manager>
<star-player>
<last>Somebloke</last>
</star-player>
</team>
</unprocessed>

Similar, but different, problems occur if, say, a team has 2 'star
players'.

How do you know which bit of un processed data belongs to which
source?
It's a good point and one I hadn't thought of.

I think that you need to think about tagging your elements with an ID
and using that ID to link the unprocessed data back to the relevant
bits of the destination data.

If any of the above is relevant to your problem, let me know and we
can look at ways around it.


Obviously this is more complex than I realised. I can't think of a way
to make your ID tagging idea work in principle (let alone in
practice). Presumably identical attributes would be added to tags that
are common to both the processed and unprocessed portions of the
destination file but unforuntately the processing we do could
completely remove or rearrange tags so matching the processed to the
unprocessed data seems impossible without writing a lot of ugly
special case code. Something I'd hoped to avoid.

Oh well, thanks for your input. I can do it the ugly way, I was just
hoping for an elegant solution.

John
Jul 20 '05 #5
On 23 Jan 2004 01:28:05 -0800, jh*******@cas.org (John Harrison)
wrote:
I don't get the namespace angle however,
You not only need to preserve this source content, you also want to
make it non-obvious to future processing. If you're transforming from
one DTD to another (frequently the target "DTD" will be (X)HTML plus a
load of class selectors) then an easy way to achieve this is to place
the copied source in a different namespace from the "useful"
destination content.
(and shouldn't it be xsl:copy-of not xsl:copy?).


Probably. Depends what you're doing and how flexible it needs to be,
but yes I think you could probably do this example with a single
xsl:copy-of

Jul 20 '05 #6
John Harrison wrote:
[snip]
So any ideas on what approach can I take to code this in an elegant
and robust way?
Provided the unprocessed material is well-formed,

<!ELEMENT unprocessed ANY>

is your friend, and will let the file be valid while allowing any
element to go in there.
I want to do some sort of 'catch all' processing that
will automatically recognise which portions of the document are
unprocessed by the rest of my XSLT code.


A specified default template would do this provided you don't mind
having multiple <unprocessed> elements in the output.

<xsl:template match="*">
<unprocessed>
<xsl:copy-of select="."/>
</unprocessed>
</xsl:template>

But it's 2.40am and I haven't tested this :-)

///Peter

Jul 20 '05 #7

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

Similar topics

5
by: K. N. | last post by:
Is there any good and fast Python module for XSLT processing ? I'm going to use XML and XSLT to generate web pages, so I need XSLT processor that will be able to transform for example a DOM object...
1
by: Ola Natvig | last post by:
Hi all I'm working with a long running, threaded server which serves HTTP requests with content which are passed through a XSLT processor. The XSLT processor I'm using is the Pyana processor. ...
2
by: Claudio Jolowicz | last post by:
How can XSLT stylesheets be used to edit, remove and add nodes specified by their position in the document tree? The XML document stores development tasks in a hierarchical way, i.e. tasks can...
2
by: chris.millar | last post by:
The class below uses the switch clause in the GetXSLT method. I want it to code it with a more OO approach does anyone have any suggestions, or change to make. cheers using System; using...
1
by: Peran | last post by:
If I create a simple xslt stylesheet I can quickly test this in VS2005 by pressing the "Show XSLT Output" button rather than running the whole solution. If I then create a xslt stylesheet with...
1
by: tslettebo | last post by:
Hi all. I've read Michael Kay's "XSLT" book, and used XSLT successfully as an HTML template system at our company (using basically the "fill-in-the-blanks" pattern of XSLT use: A template...
6
by: Pete Verdon | last post by:
Summary: Can I do an XSLT transform, in the client, of a tree of nodes taken from the displayed page DOM in IE? This works in Firefox. Hi, I'm just starting the process of rewriting part of a...
4
by: Joseph J. Kesselman | last post by:
Do you think that this is possible with an XSLT at all? Would it be XSLT is a turing-complete programming language, so it's certainly possible. People have done obscene things like writing...
12
by: Stu | last post by:
Being a newbie with XSLT transformation code please excuse my neivte. In addition, I am not sure what I want to do can be done with xslt so I apologize up front for asking anything stupid I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
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
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
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...

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.