Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 3rd, 2008, 03:00 AM
Authorized User
 
Join Date: Sep 2008
Location: , , Singapore.
Posts: 87
Thanks: 1
Thanked 0 Times in 0 Posts
Default xml tag position change

Hi,

i have an xsl and xml,i need to replace the tag position from one location to another .

xsl:

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">
    <xsl:template match="richtext">
        <html>
            <body>
                <table align="center">
                    <tr>
                        <td width="800">
                            <xsl:for-each select="par[@def='2']">
                                <xsl:copy-of select="./node()" />
                                <br />
                            </xsl:for-each>

                                <xsl:for-each select="par[@def='3']">
                                <xsl:copy-of select="./node()" />
                                <br />
                            </xsl:for-each>
                        </td>
                    </tr>
                </table>
            </body>
        </html>
    </xsl:template>
</xsl:stylesheet>


xml:


<richtext xmlns:sgx="http://www.lotus.com/dxl">
  <pardef id="2"/>
  <par def="2">
    <run>
      CapitaLand Limited’s subsidiary</run>
  </par>
  <pardef id="3"/>
  <par def="3">
    <run>
    </run>
  </par>
  <par def="3">
    <run>
   For details, please refer to the announcement and news release posted by CMTML on the SGX website </run>
    <run>
       www.sgx.com.sg</run>
  </par>
  <pardef id="4"/>
  <par def="4">
    <run>
   Fashion plus
    </run>
  </par>
  <par def="4" />
  <par def="2">
    <run>
      some text</run>
  </par>
  <par def="2">
    <run>
     some text one</run>
  </par>
  <par def="2">
     some text two
  </par>
  <par def="3">
    <run>
       some text three</run>
  </par>
</richtext>



after transformation my html view is:

<richtext xmlns:sgx="http://www.lotus.com/dxl">
  <pardef id="2"/>
  <par def="2">
    <run>
      CapitaLand Limited’s subsidiary</run>
  </par>
  <pardef id="3"/>
  <par def="3">
    <run>
    </run>
  </par>
  <par def="3">
    <run>
   For details, please refer to the announcement and news release posted by CMTML on the SGX website </run>
    <run>
       www.sgx.com.sg</run>
  </par>
  <pardef id="4"/>
  <par def="4">
    <run>
   Fashion plus
    </run>
  </par>
  <par def="4" />
  <par def="2">
    <run>
      some text</run>
  </par>
  <par def="2">
    <run>
     some text one</run>
  </par>
  <par def="2">
     some text two
  </par>
  <par def="3">
    <run>
       some text three</run>
  </par>
</richtext>



1)Is it possible to change the position of the tag

current :

<run>
       some text three</run>

required:

<run>
       some text three </run>


2)is is possible to display the order as it is in xml,as now it displays first with def=2 then def=3,my requirement is the order should be same as xml order.




Regards
Raj


Regards
RAJ

Reply With Quote
  #2 (permalink)  
Old November 3rd, 2008, 04:25 AM
Friend of Wrox
Points: 1,306, Level: 14
Points: 1,306, Level: 14 Points: 1,306, Level: 14 Points: 1,306, Level: 14
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2008
Location: Pondicherry, India
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
Default

1. Try this:

<xsl:template match="richtext">
        <html>
            <body>
                <table align="center">
                    <tr>
                        <td width="800">
                            <xsl:for-each select="par">
                                <par def="{@def}">
                                    <xsl:choose>
                                        <xsl:when test="font">


                                                <xsl:value-of select="./text()"></xsl:value-of>

                                        </xsl:when>
                                        <xsl:otherwise></xsl:otherwise>
                                    </xsl:choose>
                                    <xsl:for-each select="run">

                                <xsl:apply-templates select="."/>
                                    </xsl:for-each>

                                </par>
                                <xsl:text disable-output-escaping="yes">&lt;br/></xsl:text>
                            </xsl:for-each>
                        </td>
                    </tr>
                </table>
            </body>
        </html>
    </xsl:template>

    <xsl:template match="run">
        <run>
        <xsl:choose>
            <xsl:when test="font">

                    <xsl:value-of select="./text()"></xsl:value-of>

            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="./text()"></xsl:value-of>
            </xsl:otherwise>
        </xsl:choose>
        </run>
    </xsl:template>

2. The result is displayed as def=2 text first and def=3 text second, due to the template you have mentioned. You have processed def=2 first and then def=3 second in your stylesheet.

------
Rummy
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Transform xml to xml changing one tag. surfer97301 XSLT 2 April 21st, 2010 05:14 PM
Getting the position of a node in the original XML zvikico XSLT 8 July 17th, 2008 09:31 AM
change position of New Record row? Kimber Access VBA 3 June 27th, 2008 07:10 AM
identifying image position in incoming in xml.. kvmreddy XSLT 0 April 12th, 2006 01:14 PM
XML to (different <tag>) XML mapping Thodoris XML 4 April 27th, 2004 04:02 AM



All times are GMT -4. The time now is 08:58 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.