Quelqu'un pourrait me dire la façon la plus simple de corriger ci-dessous? J'ai actuellement un fichier contenant une variété de façons de définir des références croisées (essentiellement des liens vers d'autres pages), et je veux en convertir 2 en un seul format. Ci-dessous XML est un exemple simplifié montrant format source:XSLT manipulation de chaînes
<Paras>
<Para tag="CorrectTag">
<local xml:lang="en">Look at this section <XRef XRefType="(page xx)">(page 36)</XRef> for more information</local>
</Para>
<Para tag="InCorrectTag">
<local xml:lang="en">Look at some other section (page <XRef XRefType="xx">52</XRef>) for more information</local>
</Para>
</Paras>
Ce que je veux atteindre est le suivant:
<Paras>
<Para tag="CorrectTag">
<local xml:lang="en">Look at this section <XRef XRefType="(page xx)" XRefPage="36"/> for more information</local>
</Para>
<Para tag="InCorrectTag">
<local xml:lang="en">Look at some other section <XRef XRefType="(page xx)" XRefPage="52"/> for more information</local>
</Para>
</Paras>
L'utilisation ci-dessous xslt pour transformer le [XRef] élément
<xsl:template match="XRef">
<xsl:copy>
<xsl:attribute name="XRefType">(page xx)</xsl:attribute>
<xsl:choose>
<xsl:when test="@XRefType='(page xx)'">
<xsl:attribute name="XRefPage" select="substring-before(substring-after(.,'(page '),')')"/>
</xsl:when>
<xsl:when test="@XRefType='xx'">
<xsl:attribute name="XRefPage" select="."/>
</xsl:when>
</xsl:choose>
</xsl:copy>
</xsl:template>
me donne déjà cette sortie:
<Paras>
<Para tag="CorrectTag">
<local xml:lang="en">Look at this section<XRef XRefType="(page xx)" XRefPage="36"/>for more information</local>
</Para>
<Para tag="InCorrectTag">
<local xml:lang="en">Look at some other section (page<XRef XRefType="(page xx)" XRefPage="52"/>) for more information</local>
</Para>
</Paras>
Ce qui résout déjà la plupart de mon problème, mais je suis bloqué sur la façon dont je vais nettoyer le reste de l'élément [local] sans enlever trop d'autre contenu. Ce dont j'ai besoin, c'est quelque chose comme: si la chaîne "(page" est suivie d'un élément XRef, alors retirez-la Si la chaîne ")" est précédée d'un élément XRef, supprimez-la. Sinon, ne les touchez pas.
Des conseils sur la façon d'y remédier?
Merci, c'est l'avance!
Merci encore une fois Martin, ça fait l'affaire. Il y a une petite faute de frappe, donc si quelqu'un aime à réutiliser: [previous-sibling :: node [1] [self :: XRef]] doit être [previous-sibling :: node() [1] [self :: XRef]] . – Wokoman