Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You could use Client Side XSLT. Provide a PI into your XML documents and in the specific stylesheet include the master layout stylesheet.</p> <p>Be free to check and use <a href="http://www.aranedabienesraices.com.ar" rel="nofollow noreferrer">http://www.aranedabienesraices.com.ar</a> as example.</p> <p><strong>EDIT 3</strong>: Almost full example with recursion.</p> <p>XML document "layoutA.xml":</p> <pre><code>&lt;html xmlns:inc="include"&gt; &lt;body&gt; &lt;h1&gt;Birthday&lt;/h1&gt; &lt;dl inc:in-iter="person"&gt; &lt;dt inc:path="name"&gt;&lt;/dt&gt; &lt;dd inc:path="date"&gt;&lt;/dd&gt; &lt;/dl&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Input XML document:</p> <pre><code>&lt;data&gt; &lt;person&gt; &lt;name&gt;Bob&lt;/name&gt; &lt;date&gt;2010-02-23&lt;/date&gt; &lt;link&gt;http://example.org/bob&lt;/link&gt; &lt;/person&gt; &lt;person&gt; &lt;name&gt;Alex&lt;/name&gt; &lt;date&gt;2010-02-23&lt;/date&gt; &lt;link&gt;http://example.org/alex&lt;/link&gt; &lt;/person&gt; &lt;/data&gt; </code></pre> <p>Stylesheet:</p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:inc="include"&gt; &lt;xsl:param name="pLayout" select="'layoutA.xml'"/&gt; &lt;xsl:template match="/"&gt; &lt;xsl:apply-templates select="document($pLayout)/*"&gt; &lt;xsl:with-param name="context" select="*"/&gt; &lt;/xsl:apply-templates&gt; &lt;/xsl:template&gt; &lt;xsl:template match="@*|node()"&gt; &lt;xsl:param name="context"/&gt; &lt;xsl:copy&gt; &lt;xsl:apply-templates select="@*|node()"&gt; &lt;xsl:with-param name="context" select="$context"/&gt; &lt;/xsl:apply-templates&gt; &lt;/xsl:copy&gt; &lt;/xsl:template&gt; &lt;xsl:template match="*[@inc:path]"&gt; &lt;xsl:param name="context"/&gt; &lt;xsl:copy&gt; &lt;xsl:apply-templates select="@*"&gt; &lt;xsl:with-param name="context" select="$context"/&gt; &lt;/xsl:apply-templates&gt; &lt;xsl:value-of select="$context/*[name()=current()/@inc:path]"/&gt; &lt;/xsl:copy&gt; &lt;/xsl:template&gt; &lt;xsl:template match="*[@inc:in-iter]" priority="1"&gt; &lt;xsl:param name="context"/&gt; &lt;xsl:variable name="me" select="."/&gt; &lt;xsl:copy&gt; &lt;xsl:apply-templates select="@*"&gt; &lt;xsl:with-param name="context" select="$context"/&gt; &lt;/xsl:apply-templates&gt; &lt;xsl:for-each select="$context/*[name()=current()/@inc:in-iter]"&gt; &lt;xsl:apply-templates select="$me/node()"&gt; &lt;xsl:with-param name="context" select="."/&gt; &lt;/xsl:apply-templates&gt; &lt;/xsl:for-each&gt; &lt;/xsl:copy&gt; &lt;/xsl:template&gt; &lt;xsl:template match="*[@inc:out-iter]" priority="1"&gt; &lt;xsl:param name="context"/&gt; &lt;xsl:variable name="me" select="."/&gt; &lt;xsl:for-each select="$context/*[name()=current()/@inc:out-iter]"&gt; &lt;xsl:element name="{name($me)}" namespace="{namespace-uri($me)}"&gt; &lt;xsl:apply-templates select="$me/@*|$me/node()"&gt; &lt;xsl:with-param name="context" select="."/&gt; &lt;/xsl:apply-templates&gt; &lt;/xsl:element&gt; &lt;/xsl:for-each&gt; &lt;/xsl:template&gt; &lt;xsl:template match="@inc:path|@inc:in-iter|@inc:out-iter" priority="1"/&gt; &lt;xsl:template match="@inc:*"&gt; &lt;xsl:param name="context"/&gt; &lt;xsl:attribute name="{local-name()}"&gt; &lt;xsl:value-of select="$context/*[name()=current()]"/&gt; &lt;/xsl:attribute&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>Output:</p> <pre><code>&lt;html xmlns:inc="include"&gt; &lt;body&gt; &lt;h1&gt;Birthday&lt;/h1&gt; &lt;dl&gt; &lt;dt&gt;Bob&lt;/dt&gt; &lt;dd&gt;2010-02-23&lt;/dd&gt; &lt;dt&gt;Alex&lt;/dt&gt; &lt;dd&gt;2010-02-23&lt;/dd&gt; &lt;/dl&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Passing param <code>pLayout</code> as <code>'layoutB.xml'</code>, and this "layoutB.xml":</p> <pre><code>&lt;html xmlns:inc="include"&gt; &lt;body&gt; &lt;h1&gt;Friends&lt;/h1&gt; &lt;ul&gt; &lt;li inc:out-iter="person"&gt; &lt;a inc:href="link" inc:path="name"&gt;&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Output:</p> <pre><code>&lt;html xmlns:inc="include"&gt; &lt;body&gt; &lt;h1&gt;Friends&lt;/h1&gt; &lt;ul&gt; &lt;li&gt; &lt;a href="http://example.org/bob"&gt;Bob&lt;/a&gt; &lt;/li&gt; &lt;li&gt; &lt;a href="http://example.org/alex"&gt;Alex&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p><strong>Note</strong>: The main problem with your requeriment is the same document restriction (so, same document URI, no diferent PI, no diferent layout URI metadata) wich leaves you only to javascript to pass the layout URI param. Until browser support XPath 2.0 <code>fn:document-uri()</code> so you can parse URL query. Of course, you could use some extension (MSXSL <code>script</code>, as example) but it would be dificult to make it work cross-browser.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload