Domanda

Voglio rimuovere il './' precedente E prima cartella se non è denominata "screenshot" per qualsiasi fileref che appartiene a imagedata

Quindi da

<section xmlns="http://docbook.org/ns/docbook" version="5">
  <title>Screenshot</title>

  <para xreflabel="New Type" xml:id="manageNewType">
     <mediaobject>
        <imageobject>
           <imagedata fileref="./views/screenshots/manageType1.png" width="100%"/>
        </imageobject>
        <caption>
           <para>New Mode</para>
        </caption>
     </mediaobject>
  </para>

  <para xreflabel="Edit Type" xml:id="manageEditType">
     <mediaobject>
        <imageobject>
           <imagedata fileref="./screenshots/manageType2.png" width="100%"/>
        </imageobject>
        <caption>
           <para>Edit Mode</para>
        </caption>
     </mediaobject>
  </para>
</section>

A:Immagine dello schermo

  <para xreflabel="New Type" xml:id="manageNewType">
     <mediaobject>
        <imageobject>
           <imagedata fileref="screenshots/manageType1.png" width="100%"/>
        </imageobject>
        <caption>
           <para>New Mode</para>
        </caption>
     </mediaobject>
  </para>

  <para xreflabel="Edit Type" xml:id="manageEditType">
     <mediaobject>
        <imageobject>
           <imagedata fileref="screenshots/manageType2.png" width="100%"/>
        </imageobject>
        <caption>
           <para>Edit Mode</para>
        </caption>
     </mediaobject>
  </para>
</section>

Ecco il mio foglio di stile attuale che sembra non fare nulla per qualche motivo...

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

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

   <xsl:template match="imagedata/@fileref[starts-with(.,'./')
    and not(starts-with(.,'./screenshots/'))
    ]">
    <xsl:attribute name="fileref">
        <xsl:value-of select="substring-after(substring-after(.,'./'), '/')"/>
    </xsl:attribute>
    </xsl:template>

    <xsl:template match="imagedata/@fileref[starts-with(.,'./screenshots/')]">
    <xsl:attribute name="fileref">
        <xsl:value-of select="substring-after(.,'./')"/>
    </xsl:attribute>
    </xsl:template>
</xsl:stylesheet>

Modificare Aggiunto xmlns="http://docbook.org/ns/docbook" version="5" alla sezione.

È stato utile?

Soluzione

Questa trasformazione:

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

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

   <xsl:template match=
   "d:imagedata/@fileref
               [contains(., '/screenshots/')
              and
               not(starts-with(., 'screenshots/'))
               ]">
    <xsl:attribute name="fileref">
        <xsl:value-of select=
         "concat('screenshots/', substring-after(., '/screenshots/'))"/>
    </xsl:attribute>
    </xsl:template>
</xsl:stylesheet>

quando eseguito sul documento XML fornito:

<section xmlns="http://docbook.org/ns/docbook" version="5">
  <title>Screenshot</title>

  <para xreflabel="New Type" xml:id="manageNewType">
     <mediaobject>
        <imageobject>
           <imagedata fileref="./views/screenshots/manageType1.png" width="100%"/>
        </imageobject>
        <caption>
           <para>New Mode</para>
        </caption>
     </mediaobject>
  </para>

  <para xreflabel="Edit Type" xml:id="manageEditType">
     <mediaobject>
        <imageobject>
           <imagedata fileref="./screenshots/manageType2.png" width="100%"/>
        </imageobject>
        <caption>
           <para>Edit Mode</para>
        </caption>
     </mediaobject>
  </para>
</section>

produce il risultato desiderato e corretto:

<section xmlns="http://docbook.org/ns/docbook" version="5">
    <title>Screenshot</title>
    <para xreflabel="New Type" xml:id="manageNewType">
        <mediaobject>
            <imageobject>
                <imagedata fileref="screenshots/manageType1.png" width="100%"/>
            </imageobject>
            <caption>
                <para>New Mode</para>
            </caption>
        </mediaobject>
    </para>
    <para xreflabel="Edit Type" xml:id="manageEditType">
        <mediaobject>
            <imageobject>
                <imagedata fileref="screenshots/manageType2.png" width="100%"/>
            </imageobject>
            <caption>
                <para>Edit Mode</para>
            </caption>
        </mediaobject>
    </para>
</section>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top