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 April 24th, 2010, 05:49 AM
Authorized User
 
Join Date: Feb 2009
Posts: 31
Thanks: 6
Thanked 1 Time in 1 Post
Send a message via MSN to anil_yadav26@hotmail.com
Default [Xsltproc-XSLT 1.0]-Duplicate Author name but muliple placement as per affilation

Hi,

I have an xml file and want to print author name twice, first in <AUG> tag and second in <AUGAFF> tag. But in <AUGAFF> tag author name should be print as per the <AFF OID="af1"> and <AU ORF="af1 af3">

For example if <AU ORF="af1 af3"> is coming like this that means it should be print in <AFF OID="af1"> and <AFF OID="af2">. Please see the exmple In.xml and Out.xml for reference. I also pasted my XSLT for the same.

Could anybody help me on this.

Thanks,
Anil Yadav

Note: The text 'By' is placed according to $jid.


In.xml
Code:
<ROOT>
<AUG>
<AU ORF="af1 af3" CORF="corr1">
<NMSFX>Dr.</NMSFX>
<FNMS>Hanghui</FNMS>
<SNM>Chen</SNM>
</AU>
<AU ORF="af2">
<NMSFX>Dr.</NMSFX>
<FNMS>Alexie M.</FNMS>
<SNM>Kolpak</SNM>
</AU>
<AU ORF="af1 af2 af3">
<NMSFX>Prof.</NMSFX>
<FNMS>Sohrab</FNMS>
<SNM>Ismail&#x002D;Beigi</SNM>
</AU>
<AFF TYPE="ORG" CNY="US" OID="af1">Department of Physics, Yale University, New Haven, CT 06570 &#x00028;USA&#x00029;</AFF>
<AFF TYPE="ORG" CNY="US" OID="af2">Department of Applied Physics, Yale University New Haven, CT 06570&#x002D;8284 &#x00028;USA&#x00029;</AFF>
<AFF TYPE="ORG" CNY="US" OID="af3">Center for Research on Interface Structures and Phenomena &#x00028;CRISP&#x00029;, Yale University, New Haven, CT 06570&#x002D;8284 &#x00028;USA&#x00029;</AFF>
<CORR ID="corr1">Department of Physics, Yale University, New Haven, CT 06570 &#x00028;USA&#x00029;</CORR>
</AUG>
</ROOT>
Out.xml
Code:
<ROOT>
<AUG><TBDEL>By </TBDEL><AU ORF="af1 af3" CORF="corr1"><FNMS>Hanghui</FNMS> <SNM>Chen</SNM><TBDEL>, </TBDEL></AU><AU ORF="af2"><FNMS>Alexie M.</FNMS> <SNM>Kolpak</SNM><TBDEL>, </TBDEL></AU><AU ORF="af1 af2 af3"><FNMS>Sohrab</FNMS> <SNM>Ismail-Beigi</SNM></AU></AUG>
<AUGAFF>
<AFF TYPE="ORG" CNY="US" OID="af1"><AU ORF="af1 af3" CORF="corr1"><NMSFX>Dr.</NMSFX><FNMS>Hanghui</FNMS><SNM>Chen</SNM></AU> <AU ORF="af1 af2 af3"><NMSFX>Prof.</NMSFX><FNMS>Sohrab</FNMS><SNM>Ismail&#x002D;Beigi</SNM></AU> Department of Physics, Yale University, New Haven, CT 06570 &#x00028;USA&#x00029;</AFF>
<AFF TYPE="ORG" CNY="US" OID="af2"><AU ORF="af2"><NMSFX>Dr.</NMSFX><FNMS>Alexie M.</FNMS><SNM>Kolpak</SNM></AU> <AU ORF="af1 af2 af3"><NMSFX>Prof.</NMSFX><FNMS>Sohrab</FNMS><SNM>Ismail&#x002D;Beigi</SNM></AU> Department of Applied Physics, Yale University New Haven, CT 06570&#x002D;8284 &#x00028;USA&#x00029;</AFF>
<AFF TYPE="ORG" CNY="US" OID="af3"><AU ORF="af1 af3" CORF="corr1"><NMSFX>Dr.</NMSFX><FNMS>Hanghui</FNMS><SNM>Chen</SNM></AU> <AU ORF="af1 af2 af3"><NMSFX>Prof.</NMSFX><FNMS>Sohrab</FNMS><SNM>Ismail&#x002D;Beigi</SNM></AU> Center for Research on Interface Structures and Phenomena &#x00028;CRISP&#x00029;, Yale University, New Haven, CT 06570&#x002D;8284 &#x00028;USA&#x00029;</AFF>
<CORR ID="corr1">Department of Physics, Yale University, New Haven, CT 06570 &#x00028;USA&#x00029;</CORR>
</AUGAFF>
</ROOT>
XSLT

Code:
 <xsl:template match="AUG">
  <AUG>
  <xsl:if test="$jid='adma'">
    <xsl:attribute name="aid:pstyle">AU</xsl:attribute>
    <TBDEL><xsl:text>By </xsl:text></TBDEL>
    <xsl:apply-templates select="AU" mode="AuthorWithoutAffiliation"/>
  </xsl:if>
  <xsl:if test="$jid='SMALL'">
    <xsl:attribute name="aid:pstyle">AU</xsl:attribute>
    <xsl:apply-templates select="AU" mode="AuthorWithoutAffiliation"/>
  </xsl:if>
  </AUG>
  <AUGAFF>
   <xsl:apply-templates/>
  </AUGAFF>
 </xsl:template>

 <xsl:template match="AU" mode="AuthorWithoutAffiliation">
  <AU>
   <xsl:copy-of select="@*"/>
   <xsl:if test="position()=last()">
    <!--  <xsl:text>and </xsl:text>-->
    <xsl:apply-templates select="SNM|FNMS|EAD"/>
   </xsl:if>
   <xsl:if test="not(position()=last())">
    <xsl:apply-templates select="SNM|FNMS|EAD"/>
    <TBDEL><xsl:text>, </xsl:text></TBDEL>
   </xsl:if>
  </AU>
 </xsl:template>

 <xsl:template match="AU">
  <AU>
   <xsl:copy-of select="@*"/>
   <xsl:if test="position()=last()">
    <!--  <xsl:text>and </xsl:text>-->
    <xsl:apply-templates select="NMSFX|SNM|FNMS|EAD"/>
   </xsl:if>
   <xsl:if test="not(position()=last())">
    <xsl:apply-templates select="NMSFX|SNM|FNMS|EAD"/>
    <TBDEL><xsl:text>, </xsl:text></TBDEL>
   </xsl:if>
  </AU>
 </xsl:template>

 <xsl:template match="AU/NMSFX">
  <NMSFX>
   <xsl:apply-templates/>
  </NMSFX>
  <xsl:text> </xsl:text>
 </xsl:template>

 <xsl:template match="AU/FNMS">
  <FNMS>
   <xsl:apply-templates/>
  </FNMS>
  <xsl:text> </xsl:text>
 </xsl:template>

 <xsl:template match="EAD">
  <xsl:element name="EAD">
   <xsl:attribute name="ead"><xsl:value-of select="."/></xsl:attribute>
   <xsl:copy-of select="@*"/>
   <TBDEL><xsl:text>*</xsl:text></TBDEL>
  </xsl:element>
 </xsl:template>
 
Old April 24th, 2010, 07:10 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Here is a sample XSLT 1.0 stylesheet that makes use of EXSLT strg:tokenize which XSLT proc should support:
Code:
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:str="http://exslt.org/strings"
  exclude-result-prefixes="str"
  version="1.0">
  
  <xsl:output method="xml" indent="yes"/>
  <xsl:strip-space elements="*"/>
  
  <xsl:key name="k1" match="AU" use="str:tokenize(@ORF)"/>
  
  <xsl:template match="ROOT">
    <xsl:copy>
      <xsl:apply-templates select="AUG"/>
      <AUGAFF>
        <xsl:apply-templates select="AUG/AFF"/>
        <xsl:copy-of select="AUG/CORR"/>
      </AUGAFF>
    </xsl:copy>
  </xsl:template>
  
  <xsl:template match="AUG">
    <xsl:copy>
      <TBDEL>By </TBDEL>
      <xsl:apply-templates select="AU"/>
    </xsl:copy>
  </xsl:template>
  
  <xsl:template match="AU">
    <xsl:copy>
      <xsl:copy-of select="@* | node()"/>
      <xsl:if test="position() != last()">
        <TBDEL>, </TBDEL>
      </xsl:if>
    </xsl:copy>
  </xsl:template>
  
  <xsl:template match="AFF">
    <xsl:copy>
      <xsl:copy-of select="@*"/>
      <xsl:copy-of select="key('k1', @OID)"/>
      <xsl:copy-of select="node()"/>
    </xsl:copy>
  </xsl:template>
      

</xsl:stylesheet>
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog





Similar Threads
Thread Thread Starter Forum Replies Last Post
2 small problems, maybe movenext placement? aduggan Classic ASP Databases 1 April 24th, 2007 12:28 PM
Problem to transform xslt with xsltproc command. nadavvin XSLT 1 October 17th, 2006 03:34 PM
xsltproc not working benniog XSLT 1 October 2nd, 2006 06:56 AM
UserForm Placement over Chart. chajnik Excel VBA 1 September 9th, 2004 07:41 AM





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