Click here to Skip to main content
15,912,329 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi,
my requirement is i have to store my font type in XML and i have to read that XML in my CSS and apply that font type to my whole HTML page how can i do?
please help me


Im XMl



<displaydata>
<fonttoshow>Arial


is xslt :---
XML
<?xml version="1.0" encoding="UTF-8">
<xsl:stylesheet version=""1.0"<br" mode="hold" xmlns:xsl="#unknown" />xmlns:xsl="http://www.w3.org/1999/XSL/Transform"">

<xsl:template match="/" xmlns:xsl="#unknown">
 <html>
    <head>
      <style type="text/css">
        body
        {
           	{font-family:<xsl:value-of select="fonttoshow">;}
        }

       </style>
    </head>
  <body></xsl:value-of></xsl:template>
Posted
Updated 1-Dec-11 0:42am
v2
Comments
Sergey Alexandrovich Kryukov 28-Nov-11 11:17am    
Not clear. Could you show a fragment of your XML? What program do you want to "read" the font? XML and CSS do not read anything, this is pure data.
--SA

1 solution

You have an XML file containing layout data that you want transformed into HTML by your XSLT transform at runtime.

Yes, the .NET framework facilitates this. Here is a snipped from the sitemap on my web site that is transformed at run-time. Instead of having a manually maintained sitemap.xml for search engines.

My XML:
HTML
<site xmlns="http://redcell.ca/schema/sitemap.xsd" baseurl="http://two-red-cells.com/">
    <page id="services" type="category">
        <page id="3d modelling" type="content" />
        <page id="archiving" type="content" />
        <page id="ipad" type="content" />
        <page id="proofreading" type="content" />
        <page id="web" type="content" />
        <page id="writing" type="content" />
    </page>
    <page id="solutions" type="category">
        <page id="barcoding" type="content" />
        <page id="crowdsourcing" type="content" />
        <page id="intelligent forms" type="content" />
        <page id="nui" type="content" />
        <page id="rfid" type="content" />
        <page id="rtls" type="content" />
        <page id="social mining" type="content" />
        <page id="telemetry" type="content" />
    </page>
    <page id="information" type="category">
        <page id="sitemap" type="content" />
        <page id="contact" type="content" />
        <page id="articles" type="content" />
        <page id="mobile" type="link" />
        <page id="news" type="content" />
        <page id="surplus" type="content" />
        <page id="twitter" type="link" />
    </page>
</site>


My XSLT:
HTML
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl" xmlns:s="http://redcell.ca/schema/sitemap.xsd">
    <xsl:output method="xml" indent="yes" />

    <xsl:template match="/">
        <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
            <url>
                <loc><xsl:value-of select="s:site/@baseUrl" /></loc>
                <changefreq>daily</changefreq>
                <priority>1.0</priority>
            </url> 
            <xsl:for-each select="//s:page[@type='category']">
                <url>
                    <loc><xsl:value-of select="/s:site/@baseUrl" /><xsl:value-of select="@id" />/</loc>
                    <changefreq>daily</changefreq>
                    <priority>0.75</priority>
                </url> 
            </xsl:for-each>
            <xsl:for-each select="//s:page[@type='content']">
                <url>
                    <loc><xsl:value-of select="/s:site/@baseUrl" /><xsl:value-of select="parent::s:page/@id" />/<xsl:value-of select="@id" /></loc>
                    <changefreq>daily</changefreq>
                    <priority>0.50</priority>
                </url> 
            </xsl:for-each>
        </urlset>
        <xsl:apply-templates select="@* | node()" />
    </xsl:template>
</xsl:stylesheet>


The transformation code:
C#
using System;
using System.IO;
using System.Web.UI;
using System.Xml.Xsl;

/// <summary>
/// Dynamically transforms our XML sitemap into a google sitemap.
/// </summary>
public partial class sitemap : Page
{
    private string _language;
    private const string Stylesheet = "sitemap.xml.xslt";

    protected override void Render(HtmlTextWriter writer)
    {
        // Load the stylesheet into a transformer.
        var xslt = new XslCompiledTransform();
        var path = Path.Combine(Globals.SitePath, @"sitemaps\" + Stylesheet);
        xslt.Load(path);

        // Transform!
        var args = new XsltArgumentList();
        var filename = "sitemap." + _language + ".xml";
        path = Path.Combine(Globals.SitePath, @"sitemaps\" + filename);
        xslt.Transform(path, args, writer);
    }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900