Hello i'm having troubles with xslt and I would appreaciate greatly your help,
I've got an xml with some data I want to parse using xslt and a template file with the data structure and default values for the empty nodes.
I want to generate an xml using the template structure using the default values or the data given by the input xml depending on whether it has text or is empty.
I've tried iterating the nodes but I'm new to xsl and i don't get anything clear, thanks in advance.
Data:
<doc>
<object>
<group1>
<a>(<p>text here</p> or blank)</a>
<b>(<p>text here</p> or blank)</b>
<c>
<c1>(<p>text here</p> or blank)</c1>
<c2>(<p>text here</p> or blank)</c2>
</c>
</group1>
<group2>
<d>(<p>text here</p> or blank)</d>
</group2>
</object>
</doc>
Template:
<doc>
<object>
<group1>
<a><p>default text</p></a>
<b><p>default text</p></b>
<c>
<c1><p>default text</p></c1>
<c2><p>default text</p></c2>
</c>
</group1>
<group2>
<d><p>default text</p></d>
</group2>
</object>
</doc>
Right now I'm generating the output xml evaluating every node like this:
<xsl:variable name="file" select="document('template.xml')"/>
<a>
<xsl:choose>
<xsl:when test="//a != ''">
<xsl:copy-of select="//a/p" />
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="$file//a/p" />
</xsl:otherwise>
</xsl:choose>
</a>
<b> ... </b> ...
The code to iterate that i'm trying which results in all blank:
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="*[not(*) and not(text())]">
<xsl:copy>
<xsl:apply-templates select="$file//*[name()=name(current())]/p"/>
</xsl:copy>
</xsl:template>