This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

AW: AW: Refinement: creating namespaces in a generated script


Hi again,

close guess ;)

I get along somehow, it does not have to be a pure xsl solution. If you are
interested in what I'm doing, you can have a look at the whole stuff... some
comments are in German though.

I take an OpenOffice/StarOffice (content.xml) file as input. In the
userfield U1 I reference both a xsl-template T1 and the data D which should
be transformed. My first script generates a new script (generated.xsl). 

The second script takes the same input file. It includes the referenced
xsl-template T1, and contains a template T2 which matches the userfield U1.
The template T2 shall replace the userfield by applying T1 on D. The
references are text in the content.xml file, but they are pathes with
namespaces in this script. Thats the problem.

Better do not start reading below this line.



<!-- generateTemplate.xsl -->
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
  xmlns:xslt="xslt.xsl"
  xmlns:text="http://openoffice.org/2000/text";
  version="1.0">
  <xsl:output method="xml"/>
  <xsl:namespace-alias stylesheet-prefix="xslt" result-prefix="xsl"/>
  
  <xsl:template match="/">
    <xslt:stylesheet version="1.0">
      <xslt:include href="insertVariables.xsl"/>  <!-- contains recursive
copy -->


      <!-- include module referenced in input (start with two underscores
__script1, __script2) -->
      <xsl:for-each select="//text:variable-set[substring(@text:name, 1,
2)='__']">
        <xslt:include>
          <xsl:attribute name="href"><xsl:value-of
select="@text:name"/>.xsl</xsl:attribute>
        </xslt:include>
      </xsl:for-each>    

      <xsl:for-each select="//text:variable-set[substring(@text:name, 1,
2)='__']">
        <xslt:template>
          <xsl:variable
name="s">text:variable-set[@text:name='</xsl:variable>
          <xsl:variable name="t">'</xsl:variable>
          <xsl:variable name="u"><xsl:value-of select="."/></xsl:variable>
<!-- Path -->


          <xsl:attribute name="match"><xsl:value-of select="concat($s,
@text:name, $t, ' and text()=', $t , $u, $t, ']')"
              /></xsl:attribute>

          <xslt:apply-templates>
            <xsl:attribute name="select">
              <xsl:value-of select="concat('$variables', $u)"/> 
            </xsl:attribute>
            <xsl:attribute name="mode"> <xsl:value-of select="@text:name"/>
</xsl:attribute>
          </xslt:apply-templates>
        </xslt:template>
      </xsl:for-each>    


    </xslt:stylesheet>
  </xsl:template>


<!-- =========================

  <xsl:template name="add-namespaces">
    <xsl:param name="pfad"/>
    <xsl:param name="current-namespace"/>
    <xsl:if test="$pfad != ''"> 
    <xsl:if test="$current-namespace != substring-before($pfad, ':')">
      <token><xsl:value-of select="substring-before($pfad, ':')"/></token>

    </xsl:if>
    <xsl:call-template name="add-namespaces">
      <xsl:with-param name="pfad" select="substring-after($pfad, '/')"/>
      <xsl:with-param name="current-namespace"
select="substring-before($pfad, ':')"/>
    </xsl:call-template>

  </xsl:if>
  </xsl:template>
</xsl:stylesheet>

 ============================== -->

<!-- generated -->

<?xml version="1.0" encoding="UTF-8"?>
<xslt:stylesheet xmlns:xslt="http://www.w3.org/1999/XSL/Transform";
xmlns:text="http://openoffice.org/2000/text"; version="1.0">
<xslt:apply-templates select="$namespaces"/>
<xslt:include href="insertVariables.xsl"/>
<xslt:include href="__Adressen_jeweilsInZeile.xsl"/>

  
<xslt:template
match="text:variable-set[@text:name='__Adressen_jeweilsInZeile' and 
text()='/TOFalladressbuch:TOFalladressbuch/TOFalladressbuch:BeteiligteBehoer
den[1]
/TOFABeteiligteBehoerde:TOFABeteiligteBehoerde/TOFABeteiligteBehoerde:Adress
en']">

  <xslt:apply-templates
select="$variables/TOFalladressbuch:TOFalladressbuch/TOFalladressbuch:Beteil
igteBehoerden[1]
/TOFABeteiligteBehoerde:TOFABeteiligteBehoerde/TOFABeteiligteBehoerde:Adress
en" mode="__Adressen_jeweilsInZeile"/>
</xslt:template>
</xslt:stylesheet>



<!-- content.xml -->
...
<text:variable-set text:name="__Adressen_jeweilsInZeile"
text:value-type="string">/TOFalladressbuch:TOFalladressbuch/TOFalladressbuch
:BeteiligteBehoerden[1]/TOFABeteiligteBehoerde:TOFABeteiligteBehoerde/TOFABe
teiligteBehoerde:Adressen</text:variable-set>
...


<!-- insertVariables -->

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
  xmlns:text="http://openoffice.org/2000/text";
  xmlns:variables="http://de.fiscus.sfs.druck.variables";
  version="1.0">

  <xsl:output method="xml"/>

  <!-- Dieses Skript benötigt zwei Eingaben:
       - Das StarOffice Dokument, in dem die Ersetzungen vorgenommen werden.
Dieses wird als das normale Eingabedokument behandelt.
       - Die Variablen, die eingesetzt werden bzw. Textbausteine steuern.
Diese werden mit der document() eingelesen und in der 
         globalen Variable 'variables' gespeichert. Im Umwandler wird
Transformer mit setURIResolver ein eigener Resolver übergeben,
         der die URI 'variables' abfängt, und die benötigten xml-Daten
übergibt.  
       -->       
  <xsl:variable name="variables" select="document('variables')"/>


  <xsl:template match="/">
    <xsl:message>processing content.xml</xsl:message>
    <xsl:apply-templates/>    
  </xsl:template>

  <xsl:template match="/" mode="content">
    <xsl:copy>
      <xsl:apply-templates select="@*"/>
      <xsl:apply-templates/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*"/>
      <xsl:apply-templates/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="text()">
    <xsl:value-of select="."/>
  </xsl:template>

  <xsl:template match="text:variable-set">
    <xsl:copy>
      <!-- kopiere alle Attribute -->
      <xsl:apply-templates select="@*"/>      
      <!-- wenn nicht genau ein enthaltener text node, Abbruch mit
Fehlermeldung -->
      <!--
      <xsl:if test="not text()">
        <xsl:message terminate="yes">
          Mehr als ein Textknoten in Variablendeklaration: <xsl:value-of
select=""/>
        </xsl:message>
      </xsl:if>
      -->
      <!-- wenn sonstige nodes enthalten, Abbruch mit Fehlermeldung -->
      <xsl:if test="count(*) > 1">
        <xsl:message terminate="yes">
          Mehr als ein Knoten in Variablendeklaration: <xsl:value-of
select="."/>
        </xsl:message>        
      </xsl:if>

      <!-- Ersetzung des Namens mit Wert aus variables -->
      <xsl:choose> 
        <xsl:when
test="$variables/variables:variables/@*[local-name(.)=current()/@text:name]"
>
          <xsl:message>when</xsl:message>
          <xsl:value-of
select="$variables/variables:variables/@*[local-name(.)=current()/@text:name
]"/> 
        </xsl:when>
        <xsl:otherwise>
          <xsl:message>otherwise</xsl:message>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:copy>
  </xsl:template>

</xsl:stylesheet>
-----Ursprüngliche Nachricht-----
Von: bryan [mailto:bry@itnisk.com]
Gesendet: Mittwoch, 18. September 2002 16:16
An: xsl-list@lists.mulberrytech.com
Betreff: RE: AW: Refinement: [xsl] creating namespaces in a generated
script


>> So the namespace declaration is not needed in content.xml 
>Well I don't understand your problem at all then.
>I thought the idea was to run your generated XSLT over this file.
>If so, it'll need to be namespace well formed. If not, what's it got to
>do with your problem at hand?

I got the impression what he wants to do is to generate an open office
file and to put his own namespaced elements in there, i.e that the
namespaces he was worried about where not namespaces found inside open
office's xml format, hence the ns1:foo | ns2:foo and so forth example.


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]