Question

Je dois une feuille de style convertir mes fichiers XML DocBook afin qu'ils comprennent maintenant un xml: élément de base à mes balises de section. Comment puis-je faire pour le faire (depuis xml: base système a besoin et informations noeud ???)

Entrée:

<section xmlns="http://docbook.org/ns/docbook" xml:id="voidVisit" version="5">
<title>Void</title>

 <section>
  <title>Screenshot</title>
      <mediaobject>
          <imageobject>
              <imagedata fileref="screenshots/Dialog.png" />
          </imageobject>
      </mediaobject>
 </section>
</section>

Sortie:

      ...
      <section xml:id="void" version="5"
           xml:base="file:/C:/Projects/my/proj/trunk/spec/module/components/void.xml">
     <title>Void</title>
     <section>
        <title>Screenshot</title>
        <mediaobject>
           <imageobject>
              <imagedata fileref="screenshots/Dialog.png"/>
           </imageobject>
        </mediaobject>
     </section>
     ...
Était-ce utile?

La solution

Dans XSLT 2.0 (XPath 2.0) les fonctions static-base-uri() et base-uri() peut être utilisé pour cette fin .

Voici un exemple de travail:

<xsl:stylesheet version="2.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output omit-xml-declaration="yes"/>
    <xsl:template match="/">
     <doc xml:base="{base-uri()}"/>
    </xsl:template>
</xsl:stylesheet>

lorsque cette transformation est appliquée, est produit le résultat souhaité :

<doc xml:base="file:/C:/CVS-DDN/fxsl-xslt2/data/marrowtr.xml"/>

Ainsi, la transformation complète dans votre cas est :

<xsl:stylesheet version="2.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:d="http://docbook.org/ns/docbook">
 <xsl:output omit-xml-declaration="yes"/>

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

    <xsl:template match="/d:section">
     <xsl:copy>
       <xsl:attribute name="xml:base" select="base-uri(/)"/>
       <xsl:apply-templates select="node()|@*"/>
     </xsl:copy>
    </xsl:template>
</xsl:stylesheet>

Dans XSLT 1.0, la solution est pour passer le base-uri en tant que paramètre externe (xsl:param> global) pour la transformation.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top