Connecting Tech Pros Worldwide Help | Site Map

reverse element

Newbie
 
Join Date: Feb 2009
Posts: 15
#1: Feb 3 '09
Hai all,

I need to reverse the following element:
Eg:
<link rid="www.goldcopd.com"><comment style="inline">www.goldcopd.com</comment></link>

Should be:
<comment style="inline"><link rid="www.goldcopd.com">www.goldcopd.com</link></comment>

Can any one help me out

Thanks
Sam
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,629
#2: Feb 3 '09

re: reverse element


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
Newbie
 
Join Date: Feb 2009
Posts: 15
#3: Feb 3 '09

re: reverse element


Can you help me out how to do with XSLT
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,629
#4: Feb 3 '09

re: reverse element


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)
Newbie
 
Join Date: Feb 2009
Posts: 15
#5: Feb 3 '09

re: reverse element


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:
Expand|Select|Wrap|Line Numbers
  1. <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
Expand|Select|Wrap|Line Numbers
  1. <xsl:template match="comment[not(parent::ext-link)]">
  2.     <comment><xsl:apply-templates/></comment>
  3. </xsl:template>
Case 2:
Expand|Select|Wrap|Line Numbers
  1. <comment>Available at: </comment><ext-link ext-link-type="uri" xlink:href="www.goldcopd.com"><comment>www.goldcopd.com</comment></ext-link>
Expand|Select|Wrap|Line Numbers
  1. <xsl:template match="comment[(parent::ext-link)]">
  2. ...
  3. </xsl:template>
Please guide me how to write this.

Thanks
Sam
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,629
#6: Feb 3 '09

re: reverse element


do you want to switch the tags as they are, or do some adjustments too?
Newbie
 
Join Date: Feb 2009
Posts: 15
#7: Feb 3 '09

re: reverse element


<comment>Available at: </comment><ext-link ext-link-type="uri" xlink:href="www.goldcopd.com"><comment>www.goldcop d.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>Available at: </comment><ext-link ext-link-type="uri" xlink:href="www.goldcopd.com">See <comment>www.goldcopd.com</comment></ext-link>

For this occurance retain the XML as is..

Thank you for your help
Sam
Moderator
 
Join Date: Mar 2006
Posts: 1,103
#8: Feb 3 '09

re: reverse element


So you are only changing the <ext-link> nodes that don't have a direct text() node? Like :?
Expand|Select|Wrap|Line Numbers
  1. <xsl:template match="ext-link[not(text())][comment]">
  2.   <comment>
  3.     <xsl:copy-of select="comment/@*"/>
  4.     <xsl:copy>
  5.       <xsl:copy-of select="@*"/>
  6.       <xsl:value-of select="comment"/>
  7.     </xsl:copy>
  8.   </comment>
  9. </xsl:template>
  10.  
Or should the <xsl:value-of select="comment"/> be
like <xsl:apply-templates select="comment" mode="inside"/>?
Newbie
 
Join Date: Feb 2009
Posts: 15
#9: Feb 4 '09

re: reverse element


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