--- Begin Message ---
Recent Linux distributions (e.g. SuSE 9.1 +, Redhat 8+) have good
utilities for processing XSLT.

XSLT is the W3C standard for transforming XML into other formats.

I attach a file which does not do your job exactly but can easily be
cloned to do so.

To use it:
xsltproc rep2lyx.xsl yourfile.xml | sed s '/^  *//' > outfile.lyx

You will need to change the tagnames in the xsl file to match the tags
in your xml format. 

regards
John O'Gorman

On Fri, 2005-07-29 at 22:29, Daniel wrote:
>    Hello,
> 
>  Apologies by my poor English.
>  
>  I have a xml file as following:
> 
>    <?xml version="1.0" ?>
>    <Instruction>
>     <Title> Instruction 1 </Title>
>     <Author> Daniel </Author>
>     <Date> 29 - 07 - 2005 </Date>
>     <Objective>
>       bla bla bla bla .....
>     </Objective>
>     <Procedure>
>       1.- bla bla bla ....
>       2.- bla bla bla ....
>       3.- bla bla bla ....
>       ...
>     </Procedure>
>     <References>
>       [1] .....
>       [2] .....
>     </References>
>    </Instruction>
> 
>  And I would convert this file to a lyx file. The lyx file should be
> something as following:
> 
> ...
> ...
> \layout Title
> Instruction 1
> 
> \layout Author
> Daniel
> 
> \layout Date
> 29 - 07 - 2005
> 
> \layout Section
> Objective
> 
> \layout Standard
> bla bla bla bla .....
> 
> ...
> ...
> 
> 
>  Somebody can tell me some clue to do this conversion.
> 
>  Thanks.
> 
>           Daniel.
> 
> 
> 

--- End Message ---
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
>

<!--    21 May                                                -->
<!--    Interpret [EMAIL PROTECTED] attribute as Section Header  -->
<!--    Left adjust strings and dates; others right adjust    -->
<!--    First attempt at longtable version                    -->
<!--  ###########################################################
	Transforms XML file into LyX format
   expects: 
    document (query+) 
    query (row+)
    row (col+ )

	Status: 10 May - works 
	Features: col headers, adjusts OK 	
	Problems: extra line after </row> in header line
		  Spurious spaces before some tags (use sed to fix)
-->

<xsl:output method="text" 
	omit-xml-declaration="yes" 
	encoding="ISO-8849-1"
	indent="no"/>

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

<xsl:template match = "document">
  <xsl:call-template name="preamble"/>
  <xsl:text>\layout Section

</xsl:text><xsl:value-of select="./@title"/><xsl:text>
</xsl:text>
  <xsl:apply-templates/>
  <xsl:text>\the_end</xsl:text>
</xsl:template>

<!--   to process a Tabular query:
    0. write Tabular leadin: \begin_inset ... etc
    1. foreach row[1]/col write column alignment cells
    2. foreach row[1]/col write column headers
    3. apply templates to complete row/col processing
-->
<xsl:template match = "query">
\layout Standard
\align center

\begin_inset  Tabular
&lt;lyxtabular version="3" rows="<xsl:value-of select="count(row)+1"/>" columns="<xsl:value-of select="count(row[1]/col)"/>"&gt;
&lt;features islongtable="true" headBottomDL="true"&gt;
<xsl:for-each select="./row[1]/col">
  <xsl:variable name="align">
    <xsl:choose>
      <xsl:when test="@type='string'">left</xsl:when>
      <xsl:when test="@type='date'">left</xsl:when>
      <xsl:otherwise>right</xsl:otherwise>
    </xsl:choose>
  </xsl:variable>
  <xsl:choose>
    <xsl:when test="position()=last()">
      <xsl:text>&lt;column alignment="</xsl:text>
      <xsl:value-of select="$align"/><xsl:text>" valignment="top" leftline="true" rightline="true" width="0"&gt;
</xsl:text>
     </xsl:when>
    <xsl:otherwise>
      <xsl:text>&lt;column alignment="</xsl:text>
      <xsl:value-of select="$align"/><xsl:text>" valignment="top" leftline="true"  width="0"&gt;
</xsl:text>
    </xsl:otherwise>
   </xsl:choose>
</xsl:for-each>
  <xsl:text>&lt;row topline="true" bottomline="true" endhead="true"&gt;
</xsl:text>
<xsl:for-each select="./row[1]/col">
  <xsl:choose>
    <xsl:when test="position()=last()">
      <xsl:text>&lt;cell alignment="center" valignment="top" leftline="true" rightline="true" width="0"&gt;
\begin_inset Text

\layout Standard

</xsl:text><xsl:value-of select="@name"/><xsl:text>
\end_inset
&lt;/cell&gt;
</xsl:text>
     </xsl:when>
    <xsl:otherwise>
      <xsl:text>&lt;cell alignment="center" valignment="top" leftline="true" width="0"&gt;
\begin_inset Text

\layout Standard

</xsl:text><xsl:value-of select="@name"/><xsl:text>
\end_inset
&lt;/cell&gt;
</xsl:text>
    </xsl:otherwise>
   </xsl:choose>
  </xsl:for-each>
  <xsl:text>&lt;/row&gt;
</xsl:text>
<xsl:apply-templates/>
<xsl:text>&lt;/lyxtabular&gt;
\end_inset 
</xsl:text>
</xsl:template>

<xsl:template match = "row[position()=last()]">
  <xsl:text>&lt;row topline="true" bottomline="true"&gt;</xsl:text>
  <xsl:apply-templates/>
  <xsl:text>&lt;/row&gt;</xsl:text>
</xsl:template>

<xsl:template match = "row[position()&lt;last()]">
  <xsl:text>&lt;row topline="true" &gt;</xsl:text>
  <xsl:apply-templates/>
  <xsl:text>&lt;/row&gt;</xsl:text>
</xsl:template>

<xsl:template match="col">
   <xsl:text>&lt;cell alignment="center" usebox="none"&gt;
\begin_inset Text

\layout Standard

</xsl:text>
<xsl:value-of select="."/>
<xsl:text>
\end_inset
&lt;/cell&gt;</xsl:text>
</xsl:template>

<!--   Named template to produce LyX preamble         -->
<xsl:template name="preamble">
<xsl:text>#LyX 1.3 created this file. For more info see http://www.lyx.org/
\lyxformat 221
\textclass article
\language english
\inputencoding auto
\fontscheme default
\graphics default
\paperfontsize default
\papersize Default
\paperpackage a4
\use_geometry 0
\use_amsmath 0
\use_natbib 0
\use_numerical_citations 0
\paperorientation portrait
\secnumdepth 3
\tocdepth 3
\paragraph_separation indent
\defskip medskip
\quotes_language english
\quotes_times 2
\papercolumns 1
\papersides 1
\paperpagestyle default

</xsl:text>
</xsl:template>

</xsl:stylesheet>

Reply via email to