newbie: untangle nested attributes

I

iliad

hi,
i've the following questions:

1. why does..
<xsl:template match='dxl:text'>
<xsl:apply-templates/>
</xsl:template>
... results in "testing<BR>123"? why does it writes this? shouldn't i
use a 'value-of' to create some output?

2. i can transform this xml piece..
<richtext>
<pardef id='3'/>
<par def='3'>
jdi
<run>
<font style='bold'/>
ojd
</run>
g
</par>
</richtext>"
... only in something like this: jdi<B>odj</B>ojdg
How can I create this: jdi<B>odj</B>g

Thanks!!
iliad

----
XML:
<?xml version='1.0'?>
<document xmlns='http://www.lotus.com/dxl' version='6.5'
maintenanceversion='2.0' replicaid='C125707700457741' form='frm201'>
<item name='txt_NavigationTitle'>
<text>testing<break/>123</text>
</item>
<item name='rtf_Body'>
<richtext><pardef id='3'/><par def='3'>jdi<run><font
style='bold'/>ojd</run>g</par></richtext>
</item>
</document>

----
XSL:
<?xml version="1.0" encoding="ISO-8859-1"?>

<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:dxl='http://www.lotus.com/dxl'>

<xsl:eek:utput method="html" indent="yes"/>

<xsl:template match="/">
<html>
<body>
<table>
<tr>
<th>Item</th>
<th>Value</th>
</tr>
<xsl:for-each select="
dxl:document/dxl:item[@name='txt_NavigationTitle']|
dxl:document/dxl:item[@name='rtf_Body']">
<tr>
<td>
<xsl:apply-templates/>
</td>
<td>
</td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>

<xsl:template match='dxl:text'>
<xsl:apply-templates/>
</xsl:template>

<xsl:template match='dxl:richtext'>
<xsl:apply-templates/>
</xsl:template>

<xsl:template match='dxl:break'>
<BR/>
</xsl:template>

<xsl:template match="dxl:run/dxl:font[@style='bold']">
<B><xsl:value-of select = ".."/></B>
</xsl:template>

</xsl:stylesheet>

----
RESULT:
<html xmlns:dxl="http://www.lotus.com/dxl">
<body>
<table>
<tr>
<th>Item</th><th>Value</th>
</tr>
<tr>
<td>testing<BR>123</td><td></td>
</tr>
<tr>
<td>jdi<B>odj</B>ojdg</td><td></td>
</tr>
</table>
</body>
</html>
 
J

Joris Gillis

Hi,
Tempore 22:26:58 said:
1. why does..
<xsl:template match='dxl:text'>
<xsl:apply-templates/>
</xsl:template>
.. results in "testing<BR>123"?

Because you're code commands the XSLT processor to do so.
'<xsl:apply-templates/>' is equivalent to '<xsl:apply-templates select="node()"/>'

the 'dxl:text' element cotains two types of child nodes:
1. Text nodes (they are handled by a built-in default template that simply returns their value)
2. An element node: a 'break' elemwnt. You have defined a template for this element.
<xsl:template match='dxl:break'>
<BR/>
</xsl:template>

After the processing of the '<xsl:apply-templates/>', the result tree contains 3 child nodes as well:
1. a text node with value 'testing'
2. an elment 'BR'
3. a text node with value '123'

Because the output type was defined to be 'html', this looks after serialization like:
"testing<BR>123"

If you do not want the 'BR' element, either delete the template that matches 'dxl:break' or use 'value-of'.
2. i can transform this xml piece..
<richtext>
<pardef id='3'/>
<par def='3'>
jdi
<run>
<font style='bold'/>
ojd
</run>
g
</par>
</richtext>"
.. only in something like this: jdi<B>odj</B>ojdg
How can I create this: jdi<B>odj</B>g

Change the last template to:

<xsl:template match="dxl:run[dxl:font[@style='bold']]">
<B><xsl:value-of select = "."/></B>
</xsl:template>

regards,
 
I

iliad

joris, cool. thanks. which source could i use to figuer out more about
the difference of

match="element[element]"
match="element/element"

cheers, iliad
 
J

Joris Gillis

Tempore 16:11:47 said:
the difference of

match="element[element]"
match="element/element"

Your situation might be simplified:

the xml becomes:
<line>
<bold/>
my text
</line>

the only template rule:
<xsl:template match="line/bold">
<b><xsl:value-of select=".."/></b>
</xsl:template>

What happens during the xslt process?

1. The 'line' element is encountered. No matching template is found.
Defaults to:
<xsl:template match="*">
<xsl:apply-templates select="node()"/>
</xsl:template>
All child nodes are processed. There 2 of them: a 'bold' element (step 2) and a text node (step 3)
2. The 'bold' element is encountered. A matching template is found.
<b>my text</b> is added to the result tree.
3. The text node is encountered. Its value is added to the result tree.

end result: "<b>my text</b>my text"
____
What was my suggestion?
<xsl:template match="line[bold]">
<b><xsl:value-of select="."/></b>
</xsl:template>
(this matches any 'line' element that has a 'bold' child element)

Again, what happens during the xslt process?

1. The 'line' element is encountered. A matching template is found.
<b>my text</b> is added to the result tree.

That's it - no further processing.

end result: "<b>my text</b>"

Hope this helps,


regards,
 
I

iliad

joris, thanks for that all. your explanations were a great help for me
in undestanding xslt better..
kind regards, iliad
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,187
Latest member
RosaDemko

Latest Threads

Top