Given:
File with data:
<doc>
<a>some text(<p>text here</p>) or blank</a>
<b>same</b>
</doc>
File with default values:
<doc>
<a><p>Dummy text</p></a>
<b><p>Dummy text</p></b>
</doc>
I got this xslt to get the defaults from the second file:
$file = file path with default values
<a>
<xsl:choose>
<xsl:when test="//a!= ''">
<xsl:copy-of select="//a/p" />
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="document($file)//a/p" />
</xsl:otherwise>
</xsl:choose>
</a>
With this it works well and all, the only problem is that I would like to make an iteration through the xml nodes and make an automated process to improve scalability and save time entering every time the same condition fro each node. But I can't find a way to use the document() function with variables for the xpath, document($file)$nodexpath doesn't work.
I might be missing something, just started recently with xslt, if any of you could give me some advice I would appreciate It greatly.
Thanks in advance.
EDIT: The actual data resembles more an xml like this, it can have more deepth levels.
<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>
I've finally resolved it, I'm posting my solution here, thanks Daniel for your answer, it helped me a lot:
You could try matching any element that doesn't contain a child element or text and pull the default based off of the name.
There doesn't seem to be a reason to try to match xpaths based on your example. If your actual data is more complicated, update your question and I can update my answer.
Example:
XML Input (Added empty
a
andb
to get default values.)so_defaults.xml
XSLT 1.0
Output