Reputation: 43
Here is fragment of html content to be transformed
<div id="ln11413-1665">
<h4 class="niv2">Bijlage 5.51.3 </h4>
<div>
<div class="comblok">
<div style="color:gray;font-size:smaller;margin-left:20px;">
<div class="com comhis">
<b>
<div class="comthis">Wetshistoriek</div>
</b>
<div>Bijlage 5.51.3 vervangen bij art. 10 B. Vl. Reg. 6 februari 2004 (<i>B.S.</i>, 1 april 2004 (eerste uitg.)), met ingang van 1 april 2004 (art. 12).</div>
</div>
</div>
</div>
</div>
<div id="ln11413-2443">
...
<div class="historicalVersions" style="display:none">
<a href="ln11413#ln11413-2443" class="curmod">23 februari 2017</a>
<a href="ln11413_20170217#ln11413-2443" class="histmod">24 september 2014</a>
<a href="ln11413_20140922#ln11413-2443" class="histmod">30 juni 2006</a>
</div>
...
Currently I've got template which looks like this:
<xsl:template match="xhtml:h4[@class='artikel']">
<xsl:variable name="currentAnchor">
<xsl:value-of select="../@id" />
</xsl:variable>
<div class="row article title-bar">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates />
</xsl:copy>
<xsl:call-template name="AddHistoricAndFutureLawLinks">
<xsl:with-param name="currentAnchor" select="$currentAnchor"/>
</xsl:call-template>
</div>
</xsl:template>
And there is outcome(sorry for putting image): AddHistoricAndFutureLawLinks template generates div with "historicalversionsLink titleLinks" class
But it needs to be more generalized. Here are rules:
Upvotes: 0
Views: 72
Reputation: 167696
There is no context given in which you are using your code or that particular element, I would certainly in most cases implement 'If there is an h4 with the "Artikel" class, we do not change anything, let it be rendered as it was' by not matching on xhtml:h4[@class='artikel']
at all and rather let the identity transformation (e.g. declared in XSLT 3 as <xsl:mode on-no-match="shallow-copy"/>
or implemented as a template in XSLT 2 or 1) copy it and everything else you want to copy.
Of course you can also use e.g. <xsl:template match="xhtml:h4[@class='artikel']"><xsl:copy-of select="."/></xsl:template>
if you have no identity transformation set up or want to handle only that particular element.
The other requirements like 'If there is no h4 with the "Artikel" class' are rather vague or at least need some context as to where to check and where to add new contents.
Upvotes: 1