FitnessCenter1.xml
<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/xsl" href="html1.xslt"?>
<FitnessCenter>
<Member level="platinum" id="1">
<Name>Sabrina</Name>
<Phone type="home">123456</Phone>
<Phone type="work">78901</Phone>
<FavoriteColor>green</FavoriteColor>
<MembershipFee>340</MembershipFee>
</Member>
<Member id="2" level="gold">
<Name>Vicky</Name>
<Phone type="home">211000</Phone>
<Phone type="work">135999</Phone>
<FavoriteColor>red</FavoriteColor>
<MembershipFee>500</MembershipFee>
</Member>
<Member id="3" level="platinum">
<Name>Scott</Name>
<Phone type="home">211000</Phone>
<Phone type="work">135999</Phone>
<FavoriteColor>lightblue</FavoriteColor>
<MembershipFee>340</MembershipFee>
</Member>
</FitnessCenter>
html1.xslt
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html"/>
<xsl:template match="/">
<HTML>
<HEAD>
<TITLE>Welcome</TITLE>
</HEAD>
<!-- Use extracted value for attribute-->
<BODY bgcolor="{/FitnessCenter/Member/FavoriteColor}">
<!-- Merger with another xml document-->
<TABLE border="1" width="75%">
<TR>
<TH>Name</TH><TH>Phone(home)</TH>
</TR>
<xsl:for-each select="/FitnessCenter/Member">
<TR>
<TD>
<xsl:value-of select="Name"/>
</TD>
<TD>
<xsl:value-of select="Phone[@type='home']"/>
</TD>
<TD>
<xsl:value-of select="Phone[@type='work']"/>
</TD>
<TD>
<xsl:value-of select="FavoriteColor"/>
</TD>
</TR>
</xsl:for-each>
<xsl:variable name="fitnessCenter2" select="document('html2.xml')"/>
<xsl:for-each select="$fitnessCenter2/FitnessCenter/Member">
<TR>
<TD>
<xsl:value-of select="Name"/>
</TD>
<TD>
<xsl:value-of select="Phone[@type='home']"/>
</TD>
<TD>
<xsl:value-of select="Phone[@type='work']"/>
</TD>
<TD>
<xsl:value-of select="FavoriteColor"/>
</TD>
</TR>
</xsl:for-each>
</TABLE>
<hr/>
</BODY>
</HTML>
</xsl:template>
</xsl:stylesheet>
FitnessCenter2.xml
<?xml version="1.0" encoding="utf-8" ?>
<FitnessCenter>
<Member id="1" level="gold">
<Name>Rico</Name>
<Phone type="home">555-456</Phone>
<Phone type="work">135333</Phone>
<FavoriteColor>lightyellow</FavoriteColor>
<MembershipFee>500</MembershipFee>
</Member>
<Member id="2" level="platinum">
<Name>Tommy</Name>
<Phone type="home">333-231</Phone>
<Phone type="work">34567</Phone>
<FavoriteColor>lightblue</FavoriteColor>
<MembershipFee>340</MembershipFee>
</Member>
</FitnessCenter>
Default.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
System.Xml.XmlDocument doc = new XmlDocument();
doc.Load("D:/Training/Asp.Net/Demo/XSLDemo/1006/html1.xml");
XslCompiledTransform xslTran = new XslCompiledTransform();
xslTran.Load("D:/Training/Asp.Net/Demo/XSLDemo/1006/html1.xslt");
xslTran.Transform(doc, null, Response.OutputStream);
}
Then we get the following exception:
Execution of the 'document()' function was prohibited. Use the XsltSettings.EnableDocumentFunction property to enable it.
protected void Page_Load(object sender, EventArgs e)
{
System.Xml.XmlDocument doc = new XmlDocument();
doc.Load("D:/Training/Asp.Net/Demo/XSLDemo/1006/html1.xml");
XslCompiledTransform xslTran = new XslCompiledTransform();
xslTran.Load("D:/Training/Asp.Net/Demo/XSLDemo/1006/html1.xslt",XsltSettings.TrustedXslt,null);
xslTran.Transform(doc, null, Response.OutputStream);
}