newbie: untangle nested attributes

Discussion in 'XML' started by iliad, Sep 17, 2005.

  1. iliad

    iliad Guest

    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>
     
    iliad, Sep 17, 2005
    #1
    1. Advertising

  2. iliad

    Joris Gillis Guest

    Hi,
    Tempore 22:26:58, die Saturday 17 September 2005 AD, hinc in foro {comp.text.xml} scripsit iliad <>:

    > 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,
    --
    Joris Gillis (http://users.telenet.be/root-jg/me.html)
    Vincit omnia simplicitas
    Keep it simple
     
    Joris Gillis, Sep 18, 2005
    #2
    1. Advertising

  3. iliad

    iliad Guest

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

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

    cheers, iliad
     
    iliad, Sep 19, 2005
    #3
  4. iliad

    Joris Gillis Guest

    Tempore 16:11:47, die Monday 19 September 2005 AD, hinc in foro {comp.text.xml} scripsit iliad <>:

    > 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,
    --
    Joris Gillis (http://users.telenet.be/root-jg/me.html)
    Gaudiam omnibus traderat W3C, nec vana fides
     
    Joris Gillis, Sep 19, 2005
    #4
  5. iliad

    Joris Gillis Guest

    Joris Gillis, Sep 19, 2005
    #5
  6. iliad

    iliad Guest

    joris, thanks for that all. your explanations were a great help for me
    in undestanding xslt better..
    kind regards, iliad
     
    iliad, Sep 21, 2005
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    4
    Views:
    2,049
  2. Max
    Replies:
    1
    Views:
    515
    Joe Kesselman
    Sep 22, 2006
  3. P4trykx
    Replies:
    2
    Views:
    1,890
    bruce barker
    Jan 31, 2007
  4. james_027

    class attributes & data attributes

    james_027, Jun 20, 2007, in forum: Python
    Replies:
    2
    Views:
    412
    Bruno Desthuilliers
    Jun 20, 2007
  5. Kyle Schmitt
    Replies:
    3
    Views:
    225
    Kyle Schmitt
    Jul 24, 2007
Loading...

Share This Page