I have following XML input:
<table>
<tbody>
<tr>
<td style="width: 10px; margin-left: 10px;">td text</td>
<td style="color: red; width: 25px; text-align: center; margin-left: 10px;">
<span>span text</span>
</td>
</tr>
</tbody>
</table>
Please note that I have other nodes in the same document that should not be touched.
I want to remove certain attribute values from an element (in this case from td). Let's say I want to remove the width value within a style attribute. I don't know where in the style-attribute the width-value is set, it could be anywhere. The span in the td doesn't really matter (this and some other elements are there in the input).
I expect the output to be like this:
<table>
<tbody>
<tr>
<td style="margin-left: 10px;">td text</td>
<td style="color: red; text-align: center; margin-left: 10px;">
<span>span text</span>
</td>
</tr>
</tbody>
</table>
I prefer using XSLT1, I did not bring the replace() function to work yet (but maybe I am doing something wrong).
I tried using this XSLT:
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="td/@style">
<xsl:attribute name="style">
<xsl:value-of select="replace(., 'width:.[[:digit:]]+px;', '')" />
</xsl:attribute>
<xsl:apply-templates select="node()" />
</xsl:template>
I am still a beginner in XSLT and this above doesn't work and I did not find a solution here. Also, I don't know the width-value so I would need to replace the value with a regex (I used "width:.[[:digit:]]+px;") or something. Is there maybe a easier method that can replace every specific value? So I could remove text-align aswell without having to think of a new regex?
I really hope that you can help me with this (surely easy) problem. Thank you in advance!