Commit 5d8f1bb5404eb3534e1c84538d14a590591bd23f

Authored by Colomban Wendling
1 parent 9ad25793
Exists in python

Add support for text:h wrapping draw:frame

Showing 1 changed file with 28 additions and 14 deletions   Show diff stats
strip-frames.xsl
... ... @@ -24,7 +24,8 @@
24 24 <!-- TODO: add styles for new sections based on the frames? -->
25 25 <!-- create a derived style for each paragraph we strip from around a frame,
26 26 which should be identical but for having a 0 line height -->
27   - <xsl:for-each select="//text:p[draw:frame]">
  27 + <xsl:for-each select="//text:p[draw:frame]
  28 + |//text:h[draw:frame]">
28 29 <xsl:element name="style:style">
29 30 <xsl:variable name="style-name" select="@text:style-name"/>
30 31  
... ... @@ -56,8 +57,9 @@
56 57 <!-- moves children of a draw:p containing a draw:frame outside of itself,
57 58 because we want to replace the frame with sections, which do not belong
58 59 inside a text:p -->
59   -<xsl:template match="text:p[draw:frame]">
60   - <xsl:comment>Removed outer text:p</xsl:comment>
  60 +<xsl:template match="text:p[draw:frame] |
  61 + text:h[draw:frame]">
  62 + <xsl:comment>Removed outer <xsl:value-of select="name()"/></xsl:comment>
61 63 <xsl:copy>
62 64 <!-- FIXME: there's probably a better way to do that -->
63 65 <xsl:for-each select="@*">
... ... @@ -84,17 +86,29 @@
84 86 </xsl:template>
85 87  
86 88 <!-- this is kind of a hack, as we stripped the text:p, we add it back -->
87   -<xsl:template match="text:p/draw:frame[not(draw:text-box)] |
88   - text:p[draw:frame]/*[not(self::draw:frame)][not(self::text:p)]">
89   - <xsl:comment>Re-added text:p wrapping element</xsl:comment>
90   - <xsl:element name="text:p">
91   - <!-- TODO: add the stripped p's attributes here -->
92   - <xsl:call-template name="copy-and-recurse"/>
93   - </xsl:element>
  89 +<xsl:template match="text:p/draw:frame[not(draw:text-box)]
  90 + |text:h/draw:frame[not(draw:text-box)]
  91 + |text:p[draw:frame]/*[not(self::draw:frame)][not(self::text:p)]
  92 + |text:h[draw:frame]/*[not(self::draw:frame)][not(self::text:h)]">
  93 + <xsl:comment>Re-added <xsl:value-of select="name(..)" /> wrapping element</xsl:comment>
  94 + <!-- FIXME: there's probably a better way to do that.
  95 + Here in order to change the context (and because XSLT 1.0 doesn't have
  96 + the "select" attribute on xsl:copy), we use a xsl:for-each that matches
  97 + a single element in order to switch context -->
  98 + <xsl:variable name="self" select="."/>
  99 + <xsl:for-each select="..">
  100 + <xsl:copy>
  101 + <!-- TODO: add the stripped p's attributes here (?) -->
  102 + <xsl:for-each select="$self">
  103 + <xsl:call-template name="copy-and-recurse"/>
  104 + </xsl:for-each>
  105 + </xsl:copy>
  106 + </xsl:for-each>
94 107 </xsl:template>
95 108  
96 109 <!-- Replaces draw:frame/draw:text-box with a section -->
97   -<xsl:template match="text:p/draw:frame[count(draw:text-box) = count(*)]">
  110 +<xsl:template match="text:p/draw:frame[count(draw:text-box) = count(*)]
  111 + |text:h/draw:frame[count(draw:text-box) = count(*)]">
98 112 <xsl:comment>draw:frame</xsl:comment>
99 113 <xsl:comment>draw:text-box</xsl:comment>
100 114 <xsl:element name="text:section">
... ... @@ -107,9 +121,9 @@
107 121 <!-- companion for the above, catches frames not handled because outside of
108 122 supported elements. Should never happen, but helps debugging of unexpected
109 123 cases. -->
110   -<xsl:template match="*[not(self::text:p)][draw:frame[count(draw:text-box) = count(*)]]">
111   - <xsl:message>Unsupported input with a draw:frame not inside a text:p (but a <xsl:value-of select="name()"/>) but with draw:text-box children</xsl:message>
112   - <xsl:comment>Unsupported input with a draw:frame not inside a text:p (but a <xsl:value-of select="name()"/>) but with draw:text-box children</xsl:comment>
  124 +<xsl:template match="*[not(self::text:p) and not(self::text:h)][draw:frame[count(draw:text-box) = count(*)]]">
  125 + <xsl:message>Unsupported input with a draw:frame not inside a text:p or text:h (but a <xsl:value-of select="name()"/>) but with draw:text-box children</xsl:message>
  126 + <xsl:comment>Unsupported input with a draw:frame not inside a text:p or text:h (but a <xsl:value-of select="name()"/>) but with draw:text-box children</xsl:comment>
113 127 <xsl:call-template name="copy-and-recurse"/>
114 128 </xsl:template>
115 129  
... ...