RE: [xsl] Conditional extraction of data

Subject: RE: [xsl] Conditional extraction of data
From: "Bradley, Peter" <PBradley@xxxxxxxxxx>
Date: Mon, 8 Nov 2004 14:01:52 -0000
Phew!!!  You had me going for a moment there.

Seriously, though.  Thanks very much.  I'll give it a go tonight.  Because I'm
taking this course and working at the same time I'll have to give B&N (or more
likely Waterstones in my case) a miss, but I'll follow up the web resources
for sure.

The books I've consulted have been Schmelzer, XML and web services unleashed,
and  Ray, Learning XML (1st edn).  The former is our course text.  I'd
completely missed this (not surprising in the case of the "unleashed" book, as
I've just looked at the copy in work and it doesn't seem to mention
xsl:copy-of).  My copy of Learning xml is at home, so I'll have to check it
tonight.

I'll try to do the courteous thing and let you know how I get on.  If I don't,
feel free to think less of me!

Thanks again


Peter

 -----Original Message-----
From: 	M. David Peterson [mailto:m.david@xxxxxxxxxx]
Sent:	08 November 2004 13:46
To:	xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject:	Re: [xsl] Conditional extraction of data

ooops!

This portion:

<xsl:value-of select="foo"/> will output: "this is the value of foo"

<xsl:value-of select="foo"/> will output a copy of all the text elements
as well as the elements and there values that are descendants of foo. o

should have read...

<xsl:value-of select="foo"/> will output: "this is the value of foo"

<xsl:copy-of select="foo"/> will output a copy of all the text elements
as well as the elements and there values that are descendants of foo.

Sorry for the confusion!

<M:D/>



M. David Peterson wrote:

> Peter,
>
> I think there are a lot of people on this list that will commend you
> for your desire to learn by your own efforts and merits before asking
> for the answer.  Let me be the first...  nice job!
>
> Now... moving forward to help you with solving your dillemma.  The
> first thing you want to focus on is the difference between what
> xsl:value-of will output and what xsl:copy-of will output.  Think of
> the difference like this...  value-of will output the string value of
> the current element in context where as copy-of will make a deep copy
> of the element and all of its descendants.  So, in  other words...
> given the following XML...
>
> <foo>
>    this is the value of foo
>    <bar>this is the value of bar.<p>this is the value of a paragraph
> that is the child of bar</p></bar>
> </foo>
>
> <xsl:value-of select="foo"/> will output: "this is the value of foo"
>
> <xsl:value-of select="foo"/> will output a copy of all the text
> elements as well as the elements and there values that are descendants
> of foo. or:
>
> <foo>
>    this is the value of foo
>    <bar>this is the value of bar.<p>this is the value of a paragraph
> that is the child of bar</p></bar>
> </foo>
>
> If you were to use the xsl:copy element you could get selective of
> which elements or attributes to include in your copy.  So, if I were
> you, I would do one of two things... rush out to your local Barnes &
> Noble or Borders (or equivalent) and pick up a copy of Dr. Michael
> Kays XSLT Developers Reference OR go to the W3C and take a look at the
> XSLT 1.0 specification, and focus specifically on the above
> elements... learn all about each of them... read the sections over and
> over and over again until you finally get it... sometimes this is what
> it takes.
>
> If after all this you still are having troubles come back to the list
> and showcase the fact that you have done all that you can and you
> still are having troubles and I know more than half the people on this
> list will be more than happy to help.
>
> Best of luck to you!
>
> <M:D/>
>
> Bradley, Peter wrote:
>
>> It pays to be honest, so I'll be up-front about this.  The question
>> arises from an assignment on a course I'm doing.
>>
>> However, I don't want to cheat, so I'll try to form the question in
>> the most general way that I can:
>>
>> The purpose of the exercise is to convert some xml to html.  I have a
>> repeating element under the root - let's call it anElement.
>> Initially, the requirement was to output all its contents,
>> unchanged.  So I could do this:
>>
>> <xsl:for-each select="anElement">
>>     <xsl:value-of select="." />
>> </xsl:for-each>
>>
>> The anElement element has mixed content and would be described in a
>> DTD as follows:
>>
>> <!ELEMENT anElement (#PCDATA | tag1 | tag2 | tag3 | tag4)* >
>>
>> All the child tags contain #PCDATA only.
>>
>> The new requirement is to print all the content as before, but to
>> print the contents of tag2 (say) in italics - i.e. surround its
>> contents with <i></i> html tags.
>>
>> I've sweated over this all weekend and can't work out how to solve
>> it.  If I treat each tag individually in a for-each or an
>> apply-templates/template combination (if that makes sense), I can't
>> see how to output the #PCDATA in anElement.
>>
>> Any help would be appreciated - especially a pointer to a resource
>> that will let me work it out for myself.  I've tried the obvious
>> places like w3c schools.
>>
>> Thank for your attention
>>
>>
>> Peter

Current Thread