Subject: Re: [xsl] Weired Result of XSLT From: Jeff Sese <jsese@xxxxxxxxxxxx> Date: Tue, 22 May 2007 14:57:14 +0800 |
-- Jeff
Dear Lists-
Thanks in advance as I get all solutions of my problems by this lists only. Today I am hang-up in a weired problem as I am not able to find out the problem in xslt. Please let me know what is wrong in the xslt.
Command line java -jar saxon8.jar a.xml b.xsl >c.xml
INPUT <article article-type="review-article"> <contrib-group> <contrib> <name> <surname>aaaaa</surname> <given-names>xxxx</given-names> </name> </contrib> <contrib> <name> <surname>bbbb</surname> <given-names>yyyy</given-names> </name> </contrib> </contrib-group> </article>
XSLT
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<head>
<xsl:apply-templates select="//contrib-group"/>
</head>
</xsl:template>
<xsl:template match="//contrib-group"> <contributors> <xsl:apply-templates/> </contributors> </xsl:template>
<xsl:template match="contrib"> <xsl:if test="position()=1"> <person_name sequence="first" contributor_role="author"> <xsl:apply-templates select="name"/> </person_name> </xsl:if> <xsl:if test="position()>1"> <person_name sequence="additional" contributor_role="author"> <xsl:apply-templates select="name"/> </person_name> </xsl:if> </xsl:template>
<xsl:template match="contrib-group/contrib/name"> <xsl:if test="given-names"> <given_name> <xsl:apply-templates select="given-names"/> </given_name> </xsl:if> <surname> <xsl:apply-templates select="surname"/> </surname> <xsl:if test="suffix"> <suffix> <xsl:apply-templates select="suffix"/> </suffix> </xsl:if> </xsl:template> </xsl:stylesheet>
OUTPUT <?xml version="1.0" encoding="UTF-8"?> <head xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <contributors> <person_name sequence="additional" contributor_role="author"> <given_name>xxxx</given_name> <surname>aaaaa</surname> </person_name> <person_name sequence="additional" contributor_role="author"> <given_name>yyyy</given_name> <surname>bbbb</surname> </person_name> </contributors> </head>
Desired Output <?xml version="1.0" encoding="UTF-8"?> <head xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <contributors> <person_name sequence="first" contributor_role="author"> <given_name>xxxx</given_name> <surname>aaaaa</surname> </person_name> <person_name sequence="additional" contributor_role="author"> <given_name>yyyy</given_name> <surname>bbbb</surname> </person_name> </contributors> </head>
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Weired Result of XSLT, J. S. Rawat | Thread | Re: [xsl] Weired Result of XSLT, J. S. Rawat |
[xsl] Weired Result of XSLT, J. S. Rawat | Date | Re: [xsl] Weired Result of XSLT, J. S. Rawat |
Month |