XSLT - use one XSLT file which applies a transformation to transformed XML

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi all,
sorry if the subject is confusing, but to better explain my requirement, here it is: I have an XSLT file which I can apply to source XML which then generates my result XML. With the result XML I then need to apply another transformation on it which strips
out the empty XML elements. Is this possible to do in one template?
So for example, I have the following XSLT file which has the root template match...

<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; template <span style="color:Red; match<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; /<span style="color:Black; "<span style="color:Blue; >

<span style="color:Green; <!-- Perform all XML mapping here to generate result XML -->

<span style="color:Green; <!-- With the result XML generated from the mapping above, I apply a template to remove the empty XML elements -->

<span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; template <span style="color:Red; match<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; xmlresponse<span style="color:Black; "<span style="color:Blue; >
[/code]
<br/>
I already have a separate XSLT file which does the empty XML element removal (which is below) so am wondering how I can get to include this in the single XSLT file above so that the XML mapping and empty element removal can be done in one call to the XSLT
file.

<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; <?<span style="color:#A31515; xml <span style="color:Red; version<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1.0<span style="color:Black; " <span style="color:Red; encoding<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; UTF-8<span style="color:Black; " <span style="color:Blue; ?>
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; stylesheet <span style="color:Red; xmlns:xsl<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; http://www.w3.org/1999/XSL/Transform<span style="color:Black; " <span style="color:Red; version<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1.0<span style="color:Black; "<span style="color:Blue; >

<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; output <span style="color:Red; omit-xml-declaration<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; yes<span style="color:Black; " <span style="color:Red; indent<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; no<span style="color:Black; "<span style="color:Blue; />

<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; template <span style="color:Red; match<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; @* | node()<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; copy<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; apply-templates <span style="color:Red; select<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; @* | node()<span style="color:Black; "<span style="color:Blue; />
<span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; copy<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; template<span style="color:Blue; >

<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; template <span style="color:Red; match<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; *[not(descendant::text()[normalize-space()]) and not(descendant-or-self::*/@*)]<span style="color:Black; "<span style="color:Blue; />

<span style="color:Green; <!-- Include fixed XML Elements. -->
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; template <span style="color:Red; match<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; FixedNode1ToLeaveInResultXML | FixedNode2ToLeaveInResultXML | FixedNode2ToLeaveInResultXML<span style="color:Black; " <span style="color:Red; priority<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 3<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; copy<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; apply-templates <span style="color:Red; select<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; @* | node()<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; copy<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; template<span style="color:Blue; >

<span style="color:Blue; </<span style="color:#A31515; xsl<span style="color:Blue; :<span style="color:#A31515; stylesheet<span style="color:Blue; >
[/code]


There are some Empty XML elements that are required to stay in the result XML, which is what you can see in match for the template above (FixedNode*ToLeaveInResultXML)
Is this possible, or would i need to call the XsltTransform() method twice in my code? (which is not something I would be able to do due to the nature of my calling of the XSLT mapping.
Thanks in advance.
<hr class="sig Tryst

View the full article
 
Back
Top