Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 3rd, 2008, 03:00 AM
Authorized User
 
Join Date: Sep 2008
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

 
Old November 3rd, 2008, 04:25 AM
Friend of Wrox
 
Join Date: Jun 2008
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





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





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