Removing blank lines in XSLT

2019-01-20 04:44发布

问题:

I'm using:

<xsl:template match="material_id | location_code"></xsl:template>

To get rid of elements in the source XML called material_id and location_code, but whitespace lines remain, leaving an output XML something like:

<entries>
    <Identity>conflab1</Identity>


    <price>24.36</price>
    <pricedate>15-Jul-2010 13:35:18 UTC</price_date>
</entries>

How should I stop it from leaving the newline characters?

Thanks,

Matt

回答1:

Try:

<xsl:strip-space  elements="*"/>

at the top of the document.



回答2:

You should combine strip-space and preserve-space together, so that you strip all spaces except those you define, eg:

<xsl:preserve-space  elements="Identity price price_date"/>
<xsl:strip-space  elements="*"/>

Source: https://www.w3schools.com/xml/ref_xsl_el_strip-space.asp