Skip to content

Commit

Permalink
Merge pull request #170 from ibexa/temp_2.3_to_4.6
Browse files Browse the repository at this point in the history
  • Loading branch information
konradoboza authored Jul 4, 2024
2 parents b148e3d + 5aa307d commit 0d6ae20
Show file tree
Hide file tree
Showing 5 changed files with 472 additions and 56 deletions.
110 changes: 57 additions & 53 deletions src/bundle/Resources/richtext/stylesheets/xhtml5/edit/docbook.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
version="1.0">
<xsl:output indent="yes" encoding="UTF-8"/>

<xsl:key name="ids" match="*[@id]" use="@id"/>
<xsl:key name="ids" match="ezxhtml5:a[@name]" use="@name"/>

<xsl:template match="/ezxhtml5:section">
<section xmlns="http://docbook.org/ns/docbook"
xmlns:xlink="http://www.w3.org/1999/xlink"
Expand Down Expand Up @@ -100,13 +103,30 @@
</xsl:choose>
</xsl:template>

<xsl:template name="addUniqueIdAttribute">
<xsl:param name="attribute"/>

<xsl:if test="$attribute">
<xsl:choose>
<xsl:when test="count(key('ids', $attribute)) &gt; 1">
<xsl:attribute name="xml:id">
<xsl:value-of select="concat($attribute, '_', generate-id(.))"/>
</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="xml:id">
<xsl:value-of select="$attribute"/>
</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:template>

<xsl:template match="ezxhtml5:p" name="paragraph">
<para>
<xsl:if test="@id">
<xsl:attribute name="xml:id">
<xsl:value-of select="@id"/>
</xsl:attribute>
</xsl:if>
<xsl:call-template name="addUniqueIdAttribute">
<xsl:with-param name="attribute" select="@id"/>
</xsl:call-template>
<xsl:if test="@class">
<xsl:attribute name="ezxhtml:class">
<xsl:value-of select="@class"/>
Expand Down Expand Up @@ -140,11 +160,9 @@

<xsl:template match="ezxhtml5:pre">
<xsl:element name="programlisting">
<xsl:if test="@id">
<xsl:attribute name="xml:id">
<xsl:value-of select="@id"/>
</xsl:attribute>
</xsl:if>
<xsl:call-template name="addUniqueIdAttribute">
<xsl:with-param name="attribute" select="@id"/>
</xsl:call-template>
<xsl:if test="@class">
<xsl:attribute name="ezxhtml:class">
<xsl:value-of select="@class"/>
Expand Down Expand Up @@ -258,11 +276,9 @@
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<xsl:if test="@id">
<xsl:attribute name="xml:id">
<xsl:value-of select="@id"/>
</xsl:attribute>
</xsl:if>
<xsl:call-template name="addUniqueIdAttribute">
<xsl:with-param name="attribute" select="@id"/>
</xsl:call-template>
<xsl:if test="@title">
<xsl:attribute name="xlink:title">
<xsl:value-of select="@title"/>
Expand All @@ -283,13 +299,13 @@
<xsl:template name="link.anchor">
<xsl:param name="attribute"/>
<anchor>
<xsl:attribute name="xml:id">
<xsl:value-of select="$attribute"/>
</xsl:attribute>
<xsl:call-template name="addUniqueIdAttribute">
<xsl:with-param name="attribute" select="$attribute"/>
</xsl:call-template>
</anchor>
</xsl:template>

<xsl:template match="ezxhtml5:a[not(@name=preceding::ezxhtml5:a/@name)]">
<xsl:template match="ezxhtml5:a">
<xsl:choose>
<xsl:when test="@href">
<xsl:call-template name="link.href"/>
Expand Down Expand Up @@ -322,11 +338,9 @@
<xsl:value-of select="@class"/>
</xsl:attribute>
</xsl:if>
<xsl:if test="@id">
<xsl:attribute name="xml:id">
<xsl:value-of select="@id"/>
</xsl:attribute>
</xsl:if>
<xsl:call-template name="addUniqueIdAttribute">
<xsl:with-param name="attribute" select="@id"/>
</xsl:call-template>
<xsl:if test="contains( @style, 'text-align:' )">
<xsl:variable name="textAlign">
<xsl:call-template name="extractTextAlignValue">
Expand All @@ -349,11 +363,9 @@

<xsl:template match="ezxhtml5:ol">
<orderedlist>
<xsl:if test="@id">
<xsl:attribute name="xml:id">
<xsl:value-of select="@id"/>
</xsl:attribute>
</xsl:if>
<xsl:call-template name="addUniqueIdAttribute">
<xsl:with-param name="attribute" select="@id"/>
</xsl:call-template>
<xsl:if test="@class">
<xsl:attribute name="ezxhtml:class">
<xsl:value-of select="@class"/>
Expand All @@ -376,11 +388,9 @@

<xsl:template match="ezxhtml5:ul">
<itemizedlist>
<xsl:if test="@id">
<xsl:attribute name="xml:id">
<xsl:value-of select="@id"/>
</xsl:attribute>
</xsl:if>
<xsl:call-template name="addUniqueIdAttribute">
<xsl:with-param name="attribute" select="@id"/>
</xsl:call-template>
<xsl:if test="@class">
<xsl:attribute name="ezxhtml:class">
<xsl:value-of select="@class"/>
Expand Down Expand Up @@ -430,11 +440,9 @@
</xsl:choose>
</xsl:variable>
<xsl:element name="{$tablename}" namespace="http://docbook.org/ns/docbook">
<xsl:if test="@id">
<xsl:attribute name="xml:id">
<xsl:value-of select="@id"/>
</xsl:attribute>
</xsl:if>
<xsl:call-template name="addUniqueIdAttribute">
<xsl:with-param name="attribute" select="@id"/>
</xsl:call-template>
<xsl:if test="@class">
<xsl:attribute name="class">
<xsl:value-of select="@class"/>
Expand Down Expand Up @@ -665,11 +673,9 @@
</xsl:template>

<xsl:template name="addCommonEmbedAttributes">
<xsl:if test="@id">
<xsl:attribute name="xml:id">
<xsl:value-of select="@id"/>
</xsl:attribute>
</xsl:if>
<xsl:call-template name="addUniqueIdAttribute">
<xsl:with-param name="attribute" select="@id"/>
</xsl:call-template>
<xsl:if test="@data-href">
<xsl:attribute name="xlink:href">
<xsl:value-of select="@data-href"/>
Expand Down Expand Up @@ -712,11 +718,9 @@
<xsl:value-of select="@title"/>
</xsl:attribute>
</xsl:if>
<xsl:if test="@id">
<xsl:attribute name="xml:id">
<xsl:value-of select="@id"/>
</xsl:attribute>
</xsl:if>
<xsl:call-template name="addUniqueIdAttribute">
<xsl:with-param name="attribute" select="@id"/>
</xsl:call-template>
<xsl:if test="@class">
<xsl:attribute name="ezxhtml:class">
<xsl:value-of select="@class"/>
Expand Down Expand Up @@ -761,10 +765,10 @@
<xsl:value-of select="@class"/>
</xsl:attribute>
</xsl:if>
<xsl:if test="@id">
<xsl:attribute name="xml:id">
<xsl:value-of select="@id"/>
</xsl:attribute>
<xsl:if test="@data-ezelement='eztemplate'">
<xsl:call-template name="addUniqueIdAttribute">
<xsl:with-param name="attribute" select="@id"/>
</xsl:call-template>
</xsl:if>
<xsl:if test="contains( @style, 'text-align:' )">
<xsl:variable name="textAlign">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
xmlns:ezcustom="http://ibexa.co/xmlns/dxp/docbook/custom"
version="5.0-variant ezpublish-1.0">
<para><anchor xml:id="top"/>some anchor with a name attribute.</para>
<para><anchor xml:id="bottom"/>some anchor with a name attribute.</para>
<para>another anchor that should be removed due to lack of name uniqueness.</para>
<para><anchor xml:id="bottom_idm5"/>some anchor with a name attribute.</para>
<para><anchor xml:id="bottom_idm7"/>another anchor with the same name attribute.</para>
</section>
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
<section xmlns="http://ibexa.co/namespaces/ezpublish5/xhtml5/edit">
<p><a name="top"/>some anchor with a name attribute.</p>
<p><a name="bottom"/>some anchor with a name attribute.</p>
<p><a name="bottom"/>another anchor that should be removed due to lack of name uniqueness.</p>
<p><a name="bottom"/>another anchor with the same name attribute.</p>
</section>
Loading

0 comments on commit 0d6ae20

Please sign in to comment.