xml tag position change

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sgxbytes
    New Member
    • Sep 2008
    • 25

    xml tag position change

    Hi,

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

    xsl:
    [code=xml]
    <?xml version="1.0"?>
    <xsl:styleshe et 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>
    [/code]
    xml:
    [code=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>
    <font size="11pt" name="Arial" pitch="variable " truetype="true" familyid="20" /> www.sgx.com.sg</run>
    </par>
    <pardef id="4"/>
    <par def="4">
    <run>
    Fashion plus
    </run>
    </par>
    <par def="4" />
    <par def="2">
    <run>
    <font size="11pt" name="Arial" pitch="variable " truetype="true" familyid="20" />some text</run>
    </par>
    <par def="2">
    <run>
    <font size="11pt" name="Arial" pitch="variable " truetype="true" familyid="20" />some text one</run>
    </par>
    <par def="2">
    <font size="11pt" name="Arial" pitch="variable " truetype="true" familyid="20" />some text two
    </par>
    <par def="3">
    <run>
    <font size="11pt" name="Arial" pitch="variable " truetype="true" familyid="20" /> some text three</run>
    </par>
    </richtext>
    [/code]
    after transformation my html view is:
    [code=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>
    <font size="11pt" name="Arial" pitch="variable " truetype="true" familyid="20" /> www.sgx.com.sg</run>
    </par>
    <pardef id="4"/>
    <par def="4">
    <run>
    Fashion plus
    </run>
    </par>
    <par def="4" />
    <par def="2">
    <run>
    <font size="11pt" name="Arial" pitch="variable " truetype="true" familyid="20" />some text</run>
    </par>
    <par def="2">
    <run>
    <font size="11pt" name="Arial" pitch="variable " truetype="true" familyid="20" />some text one</run>
    </par>
    <par def="2">
    <font size="11pt" name="Arial" pitch="variable " truetype="true" familyid="20" />some text two
    </par>
    <par def="3">
    <run>
    <font size="11pt" name="Arial" pitch="variable " truetype="true" familyid="20" /> some text three</run>
    </par>
    </richtext>
    [/code]

    i require help in how to replace the ending font tag before the ending run tag

    current :
    [code=xml]
    <run>
    <font size="11pt" name="Arial" pitch="variable " truetype="true" familyid="20" /> some text three</run>
    [/code]
    required:
    [code=xml]
    <run>
    <font size="11pt" name="Arial" pitch="variable " truetype="true" familyid="20"> some text three </font> </run>
    [/code]
    Regards
    RAJ
    Last edited by jkmyoung; Nov 3 '08, 06:22 PM. Reason: code tags
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    you can condense the two <xsl:for-each>:
    [CODE=xml]<xsl:for-each select="par[@def = '2' or @def = '3']">[/CODE]
    if you want the <font> wrapped around the text (and not standalone) don't use <xsl:copy-of>. depending on the depth of the <par> node there are several possibilities.
    if it is always like your example you can write it down
    [CODE=xml]<run>
    <font>
    // copy attributes here (could be <xsl:copy-of select="descend ant::font/@*"/>)
    <xsl:value-of select="descend ant::run/text()"/>
    </font>
    </run>[/CODE]
    nevertheless have a look at <xsl:copy> you should find some useful tips (when looking in tutorials).

    regards

    PS: please use [code] tags

    Comment

    Working...