Subject: [xsl] Moving an element along with data manipulation From: "Pankaj Chaturvedi" <pankaj.chaturvedi@xxxxxxxxx> Date: Tue, 8 Apr 2008 14:39:10 +0530 |
Hi, I am trying move an xml element (along with its corresponding child elements) in my final output (<author> here to move below <title> along with extra punctuation generated thru stylesheet with in its child element). Below is my sample xml input, desired output and stylesheet defined by me. Problem: Author element is moving after <title> with desired punctuation but it is also appearing in <meta> element with same info. If I simply try to move <author>s with no data manipulation (no punctuation), its quite easy, but all I need it to remove it from <meta> and place it after <title>. Can somebody suggest where I am wrong? XML Input: ======== <?xml version="1.0" encoding="UTF-8"?> <article> <meta> <abc>xxxxxxxxx</abc> <author> <name><givenname>Mohsen</givenname><surname>Bahmani‐Oskooee</surname> </name> </author> <author> <name><givenname>Gour</givenname><inits>G.</inits><surname>Goswami</surname> </name> </author> <author> <name><givenname>Bidyut</givenname><middlename>Kumar</middlename><surname>Ta lukdar</surname></name> </author> </meta> <journaltitle>International Review of Applied Economics</journaltitle> <title><newpage pagenumber="93"/>The bilateral J‐curve: Canada versus her 20 trading partners</title> </article> Output ===== <?xml version="1.0" encoding="UTF-8"?> <article> <meta> <abc>xxxxxxxxx</abc> </meta> <journaltitle>International Review of Applied Economics</journaltitle> <title title_tt="art_title"><newpage pagenumber="93"/>The bilateral J‐curve: Canada versus her 20 trading partners</title><char> </char> <author au_st="au"><name><givenname>Mohsen</givenname><char> </char><surname>Bahmani‐Oskooee</surname></name></author><char>, </char><author au_st="au"><name><givenname>Gour</givenname><char> </char><surname>Goswami</surname></name></author><char> and </char><author au_st="au"><name><givenname>Bidyut</givenname><char> </char><surname>Talukdar</surname></name></author> </article> Stylesheet ======== <xsl:template match="author"> <xsl:copy> <xsl:attribute name="au_st">au</xsl:attribute> <xsl:copy-of select="@*"/> <xsl:element name="name"> <xsl:apply-templates select=".//givenname"/> <char><xsl:text> </xsl:text></char> <xsl:apply-templates select=".//surname"/> </xsl:element> </xsl:copy> <xsl:choose> <xsl:when test="count(following-sibling::author)=1 and count(//author)!=1"> <char><xsl:text> and </xsl:text></char> </xsl:when> <xsl:when test="count(following-sibling::author)=0"> </xsl:when> <xsl:otherwise> <char><xsl:text>, </xsl:text></char> </xsl:otherwise> </xsl:choose> </xsl:template> <xsl:template match="article/title"> <char><xsl:text>
</xsl:text></char> <xsl:element name="title"> <xsl:attribute name="title_att">art_title</xsl:attribute> <xsl:copy-of select="@*"/> <xsl:apply-templates/> </xsl:element> <char><xsl:text>
</xsl:text></char> <xsl:copy> <xsl:apply-templates select="preceding-sibling::meta/author"/> </xsl:copy> </xsl:template> Best, Pankaj Chaturvedi ============================================================================ ================ <HTML><BODY><P><hr size=1></P> <P><STRONG> Confidentiality Notice:" This message and any attachment(s) contained here are information that is confidential, proprietary to IDS Infotech Ltd. and its customers. Contents may be privileged or otherwise protected by law. The information is solely intended for the individual or the entity it is addressed to. If you are not the intended recipient of this message, you are not authorized to read, forward, print, retain, copy or disseminate this message or any part of it. If you have received this e-mail in error, please notify the sender immediately by return e-mail and delete it from your computer." </STRONG></P></BODY></HTML>
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Question regarding namesp, Chris von See | Thread | Re: [xsl] Moving an element along w, David Carlisle |
RE: [xsl] Question regarding namesp, Michael Kay | Date | Re: [xsl] Moving an element along w, David Carlisle |
Month |