reverse element

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • samueln12
    New Member
    • Feb 2009
    • 28

    reverse element

    Hai all,

    I need to reverse the following element:
    Eg:
    <link rid="www.goldco pd.com"><commen t style="inline"> www.goldcopd.co m</comment></link>

    Should be:
    <comment style="inline"> <link rid="www.goldco pd.com">www.gol dcopd.com</link></comment>

    Can any one help me out

    Thanks
    Sam
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    that depends on the circumstances. do you use XSLT or a script language, is this a part of a XML, are you only interested in this part of the XML, ...

    regards

    Comment

    • samueln12
      New Member
      • Feb 2009
      • 28

      #3
      Can you help me out how to do with XSLT

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        sure, what do you have so far? (there are some ways to accomplish the task, but they all depend on the rest of the XML and XSLT)

        Comment

        • samueln12
          New Member
          • Feb 2009
          • 28

          #5
          I am quite familer in XSLT and Perl.

          But i don't what to go for Perl. I want to use XSLT as the transformer for this.

          Case 1:
          Code:
          <comment>Available at: </comment><ext-link ext-link-type="uri" xlink:href="www.goldcopd.com"><comment>www.goldcopd.com</comment></ext-link>
          i am able to get the text
          Code:
          <xsl:template match="comment[not(parent::ext-link)]">
          	<comment><xsl:apply-templates/></comment>
          </xsl:template>
          Case 2:
          Code:
          <comment>Available at: </comment><ext-link ext-link-type="uri" xlink:href="www.goldcopd.com"><comment>www.goldcopd.com</comment></ext-link>
          Code:
          <xsl:template match="comment[(parent::ext-link)]">
          ...
          </xsl:template>
          Please guide me how to write this.

          Thanks
          Sam
          Last edited by samueln12; Feb 3 '09, 08:07 AM.

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #6
            do you want to switch the tags as they are, or do some adjustments too?

            Comment

            • samueln12
              New Member
              • Feb 2009
              • 28

              #7
              <comment>Availa ble at: </comment><ext-link ext-link-type="uri" xlink:href="www .goldcopd.com"> <comment>www.go ldcopd.com</comment></ext-link>

              The XSLT transformation should work for the above occurance. I don't want to lose data. Because this is for STM books and journals. I want to retain the attribute in their element.

              <comment>Availa ble at: </comment><ext-link ext-link-type="uri" xlink:href="www .goldcopd.com"> See <comment>www.go ldcopd.com</comment></ext-link>

              For this occurance retain the XML as is..

              Thank you for your help
              Sam

              Comment

              • jkmyoung
                Recognized Expert Top Contributor
                • Mar 2006
                • 2057

                #8
                So you are only changing the <ext-link> nodes that don't have a direct text() node? Like :?
                Code:
                <xsl:template match="ext-link[not(text())][comment]">
                  <comment>
                    <xsl:copy-of select="comment/@*"/>
                    <xsl:copy>
                      <xsl:copy-of select="@*"/>
                      <xsl:value-of select="comment"/>
                    </xsl:copy>
                  </comment>
                </xsl:template>
                Or should the <xsl:value-of select="comment "/> be
                like <xsl:apply-templates select="comment " mode="inside"/>?

                Comment

                • samueln12
                  New Member
                  • Feb 2009
                  • 28

                  #9
                  Many Thanks its working perfectly. Once again thank you very much

                  Comment

                  Working...