Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


RE: [xsl] inserting structure

From: "Michael Kay" <mike@------------>
To:
Date: 7/2/2005 6:06:00 PM
Oddly, your title says it all: you need to insert structure, but instead you
are trying to insert characters strings like "</p>" and "<p>". XSLT takes a
tree as input and produces a tree as output; to produce element nodes in the
result tree you need to use the XSLT instructions that create element nodes,
specifically xsl:element, xsl:copy, or literal results elements such as
<p/>.

I'm sorry, but I don't have time this evening to show you a solution to this
problem.

Michael Kay
http://www.saxonica.com/ 

> -----Original Message-----
> From: Manfred Staudinger [mailto:manfred.staudinger@xxxxxxxxx] 
> Sent: 02 July 2005 18:55
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] inserting structure
> 
> Hi, I'm new to both the list and xsl. I've build a test case: 
> 
> <?xml version="1.0" encoding="UTF-8" ?>
> <?xml-stylesheet type="text/xsl" href="doc1.xsl"?>
> <!DOCTYPE doc [
>   <!ELEMENT doc    (index,name)>
>   <!ELEMENT index  (EMPTY)>
>   <!ATTLIST index  
>       level1 CDATA #REQUIRED>
>   <!ELEMENT name  (#PCDATA)>
>   <!ATTLIST name  
>       reg CDATA #IMPLIED>
>    <!ENTITY HHStA "Wien, HHStA,">
> ]>
> <doc>
> <index level1="Pernstein, Vratislav von -" />
> <index level1="Philipp II. von Spanien" />
> Zeitungsbericht
> 1560 April 17, Toledo
>    Der Herr von Pernstain ist auf 8. diz von hinnen mit seiner
> gsellschafft nach Sarragossa vnd
>    Barzalana verrugkht, von dannen well er vber- 
> fol. 394r
>    farn auf Genua, Maylannd vnd durch 
>    Tyroll p[er] Wienn. Er hat dem Kunig ausser dess so er von Kay Mt.
> vnd Khu: w:e von Behem
>    wegen gethan, fur sich selbst ain schon zobln pelz vereert, Ime hat
> aber der Kunig mer nit als ain
>    Kettin von 2000 [] vereert, gleichwol er sich merers 
> verseh[en]. ...
>       D[er] Kunig soll den <name reg="Ragier Patie">Ragier
> Patie</name> angenomen haben,
>    hieuor der <name reg="Maria">Kunigin Maria</name> Camerling vnd
> hofmeist[er] In Spania
>    gwest, gibt im Jarlich 2000 Ducat[en] dem Tirgarten vnd annderm
> nach Niderlenndisch[en]
>    brauch zu wartten vnd zue zurichten.
> &HHStA; Reichskanzlei, Geschriebene Zeitungen 7, fol. 393v, 394r.
> </doc>
> 
> <?xml version="1.0" encoding="UTF-8" ?>
> <xsl:stylesheet version="1.0"
>                 
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">		
> <xsl:output method = "html" />
> <xsl:template match="/" name="replaceLineBreaks">
> <xsl:param name="string" select="." />
> <xsl:param name="switch" select="0" />
> <xsl:choose>
>    <xsl:when test="contains($string, '&#xA;')">
>       <xsl:choose>
>          <xsl:when test="starts-with($string, '      ')">
>             <![CDATA[</p><p>]]> 
>             <br />
> 	  <xsl:value-of select="$switch" />
>             <xsl:text>6*</xsl:text> 
>             <xsl:value-of select="substring-before($string, 
> '&#xA;')" />
>             <xsl:call-template name="replaceLineBreaks">
>                <xsl:with-param name="string"
> select="substring-after($string, '&#xA;')" />
>                <xsl:with-param name="switch" select="1" />
>             </xsl:call-template>
>          </xsl:when>
>          <xsl:when test="starts-with($string, '   ')">
>             <br />
> 	  <xsl:value-of select="$switch" />
>             <xsl:text>3*</xsl:text>
>             <xsl:if test="$switch=0">
> 	     <![CDATA[<p>]]>
>             </xsl:if>            
>             <xsl:value-of select="substring-before($string, 
> '&#xA;')" />
>             <xsl:call-template name="replaceLineBreaks">
>                <xsl:with-param name="string"
> select="substring-after($string, '&#xA;')" />
>                <xsl:with-param name="switch" select="1" />
>             </xsl:call-template>
>          </xsl:when>
>          <xsl:when test="starts-with($string, 'fol.')">
>             <xsl:text>[</xsl:text>
>             <xsl:value-of select="substring-before($string, 
> '&#xA;')" />
>             <xsl:text>]</xsl:text>
>             <xsl:call-template name="replaceLineBreaks">
>                <xsl:with-param name="string"
> select="substring-after($string, '&#xA;')" />
>                <xsl:with-param name="switch" select="1" />
>             </xsl:call-template>
>          </xsl:when>
>          <xsl:otherwise>
>             <br />
> 	  <xsl:value-of select="$switch" />
>             <xsl:text>x*</xsl:text>
>             <xsl:if test="$switch=1">
>                <![CDATA[</p>]]>
>             </xsl:if>            
>             <xsl:value-of select="substring-before($string, 
> '&#xA;')" />
>             <xsl:call-template name="replaceLineBreaks">
>                <xsl:with-param name="string"
> select="substring-after($string, '&#xA;')" />
>                <xsl:with-param name="switch" select="0" />
>             </xsl:call-template>
>          </xsl:otherwise>
>       </xsl:choose>
>    </xsl:when>
>    <xsl:otherwise>
>       <xsl:value-of select="$string" />
>    </xsl:otherwise>
> </xsl:choose>
> </xsl:template>
> </xsl:stylesheet>
> 
> wich gives the output (Firefox 1.04):
> 
> 0x*
> 0x*
> 0x*Zeitungsbericht
> 0x*1560 April 17, Toledo
> 03* <p> Der Herr von Pernstain ist auf 8. diz von hinnen mit seiner
> gsellschafft nach Sarragossa vnd
> 13* Barzalana verrugkht, von dannen well er vber- [fol. 394r]
> 13* farn auf Genua, Maylannd vnd durch
> 13* Tyroll p[er] Wienn. Er hat dem Kunig ausser dess so er von Kay Mt.
> vnd Khu: w:e von Behem
> 13* wegen gethan, fur sich selbst ain schon zobln pelz vereert, Ime
> hat aber der Kunig mer nit als ain
> 13* Kettin von 2000 [] vereert, gleichwol er sich merers 
> verseh[en]. ... </p><p>
> 16* D[er] Kunig soll den Ragier Patie angenomen haben,
> 13* hieuor der Kunigin Maria Camerling vnd hofmeist[er] In Spania
> 13* gwest, gibt im Jarlich 2000 Ducat[en] dem Tirgarten vnd annderm
> nach Niderlenndisch[en]
> 13* brauch zu wartten vnd zue zurichten.
> 1x* </p> Wien, HHStA, Reichskanzlei, Geschriebene Zeitungen 
> 7, fol. 393v, 394r.
> 
> I wanted to get for example <p> and other stuff inserted, but had to
> cover it by cdata to become well formed. Also the recursive template
> prevents me from adding html header information.
> In addition to a solution I would appreciate poiters to 
> further readings
> about this...
> 
> Manfred Staudinger, Vienna, Austria


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent