Reputation: 371
I have a XML called "map.xml" which calls another xml "map1.xml".Map.xml has reference to map.xsl.
In XSLT, i need to write the code to get the node value present in map1.xml? Can anyone of you please suggest a solution for this?
Below code specific to DITA standards
map1.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!-- code to refer XSLT -->
<map title="DITA Topic Map">
<topicref href="client.xml"/>
</map>
map2.xml:
<?xml version="1.0" encoding="UTF-8"?>
<concept id="map2">
<title>Client Rights</title>
<conbody>
<p>Part of your job as a healthcare provider.</p>
</conbody>
</concept>
Upvotes: 0
Views: 813
Reputation: 276
I think, the sources should actually look like this (with a reference to a DTD or a schema, not to a styleheet):
map.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE map PUBLIC "-//OASIS//DTD DITA Map//EN" "map.dtd">
<map title="DITA Topic Map">
<topicref href="client.xml"/>
</map>
client.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE concept PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd">
<concept id="client.xml">
<title>Client Rights</title>
<conbody>
<p>Part of your job as a healthcare provider.</p>
</conbody>
</concept>
David's suggestion is correct, it gives you the following result:
Part of your job as a healthcare provider.
To refine on this: To make use of DITA's specialization feature, you'd rather use something like this:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">
<xsl:output omit-xml-declaration="yes"/>
<xsl:template match="*[contains(@class, ' map/topicref ') and @href]">
<xsl:variable name="topic" select="document(@href, .)"/>
<xsl:value-of select="$topic//*[contains(@class, ' topic/p ')]"/>
</xsl:template>
</xsl:stylesheet>
With the sample data, this leads to the same result. But if you had a specialized paragraph element <myp> derived from <p>, you could still use the same transformation for the new element.
Upvotes: 1
Reputation: 399
Using the XSLT document() function looks like the way to go.
For example, to get the content/value of the p element in map2.xml:
<xsl:value-of select="document('map2.xml')/concept/conbody/p"/>
Have not tested this on your example, but that's what I would try!
Upvotes: 3
Reputation: 791
Use the XSLT document() function to access nodes in a separate XML document. A simple example (courtesy of w3schools.com) can be found here.
I'm a new user, so SO is preventing me from posting a second link in my answer. Here's the best I can do: the XSLT standard's explanation of document() can be found at www.w3.org/TR/xslt#document.
Upvotes: 1