Connecting Tech Pros Worldwide Help | Site Map

XLST - Help needed to write the XSL

  #1  
Old June 24th, 2008, 12:39 PM
Newbie
 
Join Date: Jun 2008
Posts: 8
Hi,

I want to create a .XSL to transform a XML document like below :


?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>

<nplbiblio >

<document >
<xp>XP000571793</xp>
<doi>10.1117/12.205299</doi>
</document >

<document >
<xp>XP000571816</xp>
<doi>10.1117/12.171773</doi>
</document >

</nplbiblio>



into


<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE nplbiblio SYSTEM "npl-entities.dtd">
<nplbiblio xmlns:npl="http://www.epo.org/npl" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="npldoc v2.0.xsd" rundate="20080123" filename="AIP_43.xml">

<document creadate="20080523" status="N">
<xp>XP000571793</xp>
<attribs>
<attrib name="doi-art">10.1117/12.20529</attrib>
</attribs>
</document>

<document creadate="20080523" status="N">
<xp>XP000571816</xp>
<attribs>
<attrib name="doi-art">10.1117/12.171779</attrib>
</attribs>
</document>

</nplbiblio>



Can someone help me ?

I have tried different writting different xsl with no success...

Many thanks

Sarah
  #2  
Old June 24th, 2008, 04:14 PM
Moderator
 
Join Date: Mar 2006
Posts: 1,103

re: XLST - Help needed to write the XSL


Can you post the sample of your xsl so far? It might just be something really simple you're getting caught up on.
  #3  
Old June 25th, 2008, 07:51 AM
Newbie
 
Join Date: Jun 2008
Posts: 8

re: XLST - Help needed to write the XSL


<?xml version='1.0' ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:template match="/">

<nplbiblio>

<xsl:for-each select="a:nplbiblio/a:document">
<document status="n">
<xp>
<xsl:value-of select="a:xp"/>
</xp>

<attribs>
<attrib name="doi-art">
<xsl:value-of select="a:doi"/>
</attrib>
</attribs>

</document>
</xsl:for-each>
</nplbiblio>
</xsl:template>
</xsl:stylesheet>
  #4  
Old June 25th, 2008, 07:52 AM
Newbie
 
Join Date: Jun 2008
Posts: 8

re: XLST - Help needed to write the XSL


Thanks for the help ! I am not a XML expert and trying my best ...;}
  #5  
Old June 26th, 2008, 08:44 PM
Moderator
 
Join Date: Mar 2006
Posts: 1,103

re: XLST - Help needed to write the XSL


Note the use of <xsl:output/>, the declaration of other namespaces, and the use of <xsl:copy-of/>
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0"?>
  2. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:npl="http://www.epo.org/npl" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  3.     <xsl:output method="xml" doctype-system="npl-entities.dtd"/>
  4.     <xsl:template match="/">
  5.         <nplbiblio>
  6.             <xsl:attribute name="xsi:noNamespaceSchemaLocation">npldoc v2.0.xsd</xsl:attribute>
  7.             <xsl:attribute name="rundate">20080123</xsl:attribute>
  8.             <xsl:for-each select="nplbiblio/document">
  9.                 <document status="n">
  10.                     <xsl:attribute name="creadate">20080123</xsl:attribute>
  11.                     <xsl:copy-of select="xp"/>
  12.                     <attribs>
  13.                         <attrib name="doi-art">
  14.                             <xsl:value-of select="doi"/>
  15.                         </attrib>
  16.                     </attribs>
  17.                 </document>
  18.             </xsl:for-each>
  19.         </nplbiblio>
  20.     </xsl:template>
  21. </xsl:stylesheet>
  22.  
  #6  
Old June 27th, 2008, 08:47 AM
Newbie
 
Join Date: Jun 2008
Posts: 8

re: XLST - Help needed to write the XSL


A million thanks ... I was indeed a bit far off !

I am currently studying closer the difference between "<xsl:copy-of> and <xsl:cvalue-of>.

Still learning ....
Reply