Link to home
Create AccountLog in
Avatar of tia_kamakshi
tia_kamakshiFlag for United Arab Emirates

asked on

Reading another xml from xslt and append the exising

Hi Experts,

My xslt is running on some xml.

Now I need to create a node list (Its basically xml file) from my new xml file while reading from same xslt


I mean I need to read another xml below

<?xml version="1.0" encoding="UTF-8"?>
<minisitemaps>
	<minimap name="news">
		<location>about/News/News_SiteMap.aspx</location>
		<lastmodified>hgfhfg</lastmodified>
		<addpuburl>true</addpuburl>
	</minimap>
	<minimap name="FAQ">
		<location>Help/faq/FAQ_SiteMap.aspx</location>
		<lastmodified>jhkhkl</lastmodified>
		<addpuburl>true</addpuburl>
	</minimap>
</minisitemaps>

Open in new window



and wants to create following output

<sitemap>
	<loc>
		http://www.xyz.com/about/News/News_SiteMap.aspx
	</loc>
	<lastmod>
		hgfhfg
	</lastmod>
</sitemap>

<sitemap>
	<loc>
		http://www.xyz.com/Help/faq/FAQ_SiteMap.aspx
	</loc>
	<lastmod>
		jhkhkl
	</lastmod>
</sitemap>

Open in new window


It should create the nodes from template "DynamicPages"

<xsl:template match="??????" mode="DynamicPages">

Open in new window


Here is my sample xslt
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:utils="urn:XSLTExtensions" exclude-result-prefixes="utils">


	<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" omit-xml-declaration="no" />

	<xsl:param name="hostPrefix">http://www.xyz.com</xsl:param>
	<xsl:variable name="sitemap">/sitemap.xml</xsl:variable>
	<xsl:variable name="minisitemap">/minisitemap.xml</xsl:variable>


	<xsl:variable name="News_sitemap">/about/News/News_SiteMap.aspx</xsl:variable>
	<xsl:variable name="FAQ_sitemap">/help/faqs/FAQ_SiteMap.aspx</xsl:variable>

	<xsl:template match="/">

		<sitemapindex xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/siteindex.xsd">
			<xsl:variable name="modified" select="utils:FileModified($sitemap)" />
			<xsl:if test="$modified != ''">
				<sitemap>
					<loc>
						<xsl:value-of select="concat($hostPrefix, $sitemap)"/>
					</loc>
					<lastmod>
						<xsl:value-of select="$modified"/>
					</lastmod>
				</sitemap>

			</xsl:if>
			<xsl:apply-templates select="/sitedata/region/site/language" mode="DynamicPages"/>


		</sitemapindex>
	</xsl:template>

<xsl:template match="??????" mode="DynamicPages">
		<xsl:if test="$modified != ''">
			<sitemap>
				<loc>
					<xsl:value-of select="concat($hostPrefix, @url, $location)"/>
				</loc>
				<lastmod>
					<xsl:value-of select="$modified"/>
				</lastmod>
			</sitemap>
		</xsl:if>
	</xsl:template>
</xsl:stylesheet>

Open in new window




Please help me do the needful

Regards
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

At the location where you want the sitemaps to start, call out for the other doc

<xsl:apply-templates select="document('otherdocname')" mode="DynamicPages"/>

All you need then is handling that seperate tree using the same mode

<xsl:template match="minisitemaps" mode="DynamicPages">
Avatar of tia_kamakshi

ASKER

Many Thanks, it works great.

I wanted to put 'otherdocname' path in variable.

If otherdocname does not exists or otherdocname is blank then I do not wanted to call template

<xsl:apply-templates select="document('otherdocname')" mode="DynamicPages"/>

Basically I wanted to make this generic. If document is passed in varaiable as parameter then tempplate should call else not

Please suggest
ASKER CERTIFIED SOLUTION
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Many Many Thanks