|
<Root>
<Products>
<Item ItemColor="Red" ItemName="Item1"/>
<Item ItemColor="White" ItemName="Item2"/>
<Item ItemColor="Blue" ItemName="Item2"/>
</Products>
<Desciptions>
<Color ColorName="Red" ColorId="15"/>
<Color ColorName="White" ColorId="14"/>
<Color ColorName="Blue" ColorId="13"/>
</Desciptions>
</Root>
<xsl:template match="/">
<xsl:for-each select="Products/Item">
<tr>
<td><xsl:value-of select="ItemColor" /></td>
<td> ? Right here I want the ColorId of the
ColorName that matches ItemColor found by the previous select ?</td>
</tr>
</xsl:for-each>
</xsl:template match="/">
Thank You for reading this post.
modified on Friday, July 10, 2009 6:12 PM
|
|
|
|
|
Throw the value into a variable then XPath with a condition on the variable, like this:
<xsl:for-each select="Products/Item">
<xsl:variable name="colorname" select="@ItemColor"/>
<tr>
<td><xsl:value-of select="$colorname"/></td>
<td><xsl:value-of select="//Color[@ColorName=$colorname]/@ColorId"/></td>
</tr>
</xsl:for-each>
Jeremy Likness
http://csharperimage.jeremylikness.com/
|
|
|
|
|
Thanks , you have solved my problem and
enlightened me on the use of variables .
Very much appreciated .
|
|
|
|
|
An alternative solution without variables:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html"/>
<xsl:template match="/">
<xsl:for-each select="//Products/Item">
<tr>
<td><xsl:value-of select="@ItemColor" /></td>
<td><xsl:value-of select="//Desciptions/Color[@ColorName=current()/@ItemColor]/@ColorId"/></td>
</tr>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
current() retrieves the context node of the scope surrounding the select attribute, i.e. the node currently selected by the for-each element in this case.
Here's another solution, using an XSLT key element. This approach is very useful when there's a large number of things to lookup in.
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html"/>
<xsl:key name="color-name-to-id" match="//Desciptions/Color/@ColorId" use="../@ColorName"/>
<xsl:template match="/">
<xsl:for-each select="//Products/Item">
<tr>
<td><xsl:value-of select="@ItemColor" /></td>
<td><xsl:value-of select="key('color-name-to-id', @ItemColor)"/></td>
</tr>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Hi
I am doing a code generation app. using .Net 3.5.
I wish to know if it is possible to generate multiple code files from a single xslt file.
I know that it can be accomplished in XSLT 2.0 using result-document tag.
Is it possible using XSLT 1.0 ?
Thanks
Fadi
|
|
|
|
|
Exslt[^] provides the exsl:document[^] element - but that only seems to be implemented in libxslt.
As you're using .NET, though, you could implement something like exsl:document using an Extension Object[^].
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Thank you Stuart
But can you clarify some more things?
My xml file is
<?xml version="1.0" encoding="utf-8" ?>
<bookstore>
<book genre="autobiography" publicationdate="1981" ISBN="1-861003-11-0">
<title>The Autobiography of Benjamin Franklin</title>
<author>
<first-name>Benjamin</first-name>
<last-name>Franklin</last-name>
</author>
<price>8.99</price>
</book>
<book genre="novel" publicationdate="1967" ISBN="0-201-63361-2">
<title>The Confidence Man</title>
<author>
<first-name>Herman</first-name>
<last-name>Melville</last-name>
</author>
<price>11.99</price>
</book>
<book genre="philosophy" publicationdate="1991" ISBN="1-861001-57-6">
<title>The Gorgias</title>
<author>
<name>Plato</name>
</author>
<price>9.99</price>
</book>
</bookstore>
My xslt file is
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:output="urn:output">
<xsl:template match="bookstore">
<bookstore>
<xsl:for-each select="book">
<book>
<xsl:copy-of select="node()"/>
<new-price>
<xsl:value-of select="output:SaveOutput(@genre, node())"/>
</new-price>
</book>
</xsl:for-each>
</bookstore>
</xsl:template>
</xsl:stylesheet>
C# code goes like
private void ExtensionTest()
{
XslCompiledTransform xslt = new XslCompiledTransform();
xslt.Load("extension.xslt");
XsltArgumentList xslArg = new XsltArgumentList();
OutputSaver obj = new OutputSaver();
xslArg.AddExtensionObject("urn:output", obj);
using (XmlWriter w = XmlWriter.Create("output.xml"))
{
xslt.Transform("books.xml", xslArg, w);
}
}
public class OutputSaver
{
public void SaveOutput(string fileName, string node)
{
StreamWriter s = new StreamWriter(fileName);
s.Write(node);
s.Flush();
}
}
Now I have 2 issues
* How to pass the xslt node content to SaveOutput method in c#
* How avoid specifying an output file in Trnasform method of XslCompiledTransform (This is to avoid generating an addtional file with the files generated using extennsion method)
Thank you
Fadi
|
|
|
|
|
I got one more query. Will it be possible by embedding script in xslt?
I tried the following way
Xslt file
?xml version="1.0" encoding="utf-8"?>
<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:user="urn:myscripts"
>
<xsl:output method="xml" indent="yes"/>
<msxsl:script language="C#" implements-prefix="user">
<![CDATA[
public void SaveOutput(string fileName)
{
System.IO.TextWriter t = new System.IO.StreamWriter(fileName);
t.Write("got it");
t.Flush();
}
]]>
</msxsl:script>
<xsl:template match="@* | node()">
<xsl:value-of select="user:SaveOutput('d:\testing.txt')"/>
</xsl:template>
</xsl:stylesheet>
My C# code is
private void ScriptTest()
{
XsltSettings settings = new XsltSettings();
settings.EnableScript = true;
XslCompiledTransform trs = new XslCompiledTransform();
trs.Load("Custom.xslt", settings, new XmlUrlResolver());
StreamWriter writer = new StreamWriter(@"e:\samples.txt");
trs.Transform(@"E:\\9.xml", null, writer);
writer.Flush();
writer.Close();
}
But when I run the code, I get en error like
IOException unhandled - The device is not ready
Thank you
Fadi
|
|
|
|
|
|
Hello all,
I am rendering my page using XSL.At place I am using sorting using xsl sort.But this need to be dynamic i e user can sort by some specific fiend by his own choice.
So I have to put select as dynamic which I am passing to xsl as a parameter as
<code><xsl:param name="SortName" select="Name" />
<xsl:param name="SortDataType" select="text" /></code>
Now I am accessing these parameter in xsl:sort tag as
<code> <xsl:sort select="$SortName" data-type='{$SortDataType}'/></code>
but its not working...
Waiting for your reply..
|
|
|
|
|
If SortName is the name of an element, try something like this:
<xsl:sort select="./*[name()=$SortName]"/>
[edit]Or if SortName is the name of an attribute, then use this:
<xsl:sort select="./@*[name()=$SortName]"/>
[/edit]
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Hello friends,
How can i implement RSS feeds in wy website.
Thanks in ADvance.
With regards,
MAHESH.K
|
|
|
|
|
Have you tried google yet?
|
|
|
|
|
I've tried more and found out how to create xml.but i didn't get how to implement in my web page
modified on Friday, July 3, 2009 9:11 AM
|
|
|
|
|
An RSS feed will have an associated URL that will fetch the XML making up the RSS feed. You web site should respond to requests for that URL by returning the RSS's XML. Not tricky.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Try this code for RSS feeds.
<div align="center">
<asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="http://www.hindu.com/rss/07hdline.xml"
XPath="rss/channel/item"></asp:XmlDataSource>
</div>
<div align="center">
<asp:DataList ID="DataList1" runat="server" BackColor="White" BorderColor="#DEDFDE"
BorderStyle="None" BorderWidth="1px" CellPadding="4" DataSourceID="XmlDataSource1"
ForeColor="Black" GridLines="Vertical" Width="500px">
<FooterStyle BackColor="#CCCC99" />
<SelectedItemStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
<AlternatingItemStyle BackColor="White" />
<ItemStyle BackColor="#F7F7DE" />
<HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
<ItemTemplate>
<asp:Label Text="Title : " Font-Bold="true" ForeColor="blue" ID="lbltitle" runat="server"></asp:Label><%#XPath("title")%>
<hr color="#0099ff" />
<asp:Label Text="Link : " Font-Bold="true" ForeColor="blue" ID="Label1" runat="server"></asp:Label><a target="_blank" href='<%#XPath("link")%>' ><%#XPath("link")%></a>
<hr color="#0099ff" />
<asp:Label Text="Description : " Font-Bold="true" ForeColor="blue" ID="Label2" runat="server"></asp:Label><%#XPath("description")%><br />
<hr color="#0099ff" />
<asp:Label Text="Published Date : " Font-Bold="true" ForeColor="blue" ID="Label3" runat="server"></asp:Label><%#XPath("pubDate")%><br />
<hr color="#0099ff" /> <br />
</ItemTemplate>
</asp:DataList>
</div>
you should specify the DataFile and XPath in "asp:XmlDataSource" - you should get these information from any RSS provided websites.
|
|
|
|
|
Thank u Mr.KKarthik2000. It is really helpful for me.Now only i get a clear concept of Rss.Thank u once again.I have no words to greet u.
|
|
|
|
|
hello friends
i wanna make a dektop news ticker which rotates my personal news or message worldwide whenever that particular application is installed on any pc . DESKTOP NEWS TICKER by www.mioplant.com provides an easy way 2 build but i'm not getting that.
it uses some rss feeds and xml kind of fundas plz tell how to rotate the information which can be changed time 2 time anytime.
thanks
|
|
|
|
|
|
Firstly - note the forum title "XML/XSL" - I don't think your query is entirely appropriate for this forum?
Anyway - I would hope the answer is "you can't, no way, no how, without some helper software already installed on the PC" - sounds like a recipe for malware hell.
But of course, Microsoft have a solution of sorts - ClickOnce[^].
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Stuart Dootson wrote: Firstly - note the forum title "XML/XSL" - I don't think your query is entirely appropriate for this forum?
It was imho the Closest site I could find to HTML
Stuart Dootson wrote: Anyway - I would hope the answer is "you can't, no way, no how, without some helper software already installed on the PC" - sounds like a recipe for malware hell.
Well, as I own all the PC's on which to use this, (and as I also own the CPP Code that I want to run) installing helper software is no problem.
The Link was Usefull.
Thanks,
Bram van Kampen
|
|
|
|
|
Hi..
I am using a function to format the date values which are read from the XML document,but in XSLT while using the following coding i am receiveing only empty value in the DOB parameter.How can i solve the issue
xsl:value-of select="DateTimeConverter:ToDateTimeFormat(DOB, 'dd-MMM-
YYYY')"
DOB is the short form of Date of birth node below is the XML structure
< Name > Guest < /Name >
< DOB > 2009-06-12T02:00:47.187 < /DOB >
< Age > 25 < /Age >
while reading the DOB node i am reteriving only empty values how can i solve this
Mahesh.J
Thanks
Mahesh.J
|
|
|
|
|
Are you using the class from this page[^]? If so, have you tried the samples to verify that you've got the code installed such that it can be resolved by the XSLT engine?
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
I am using the class which is placed in the APP_Code folder
|
|
|
|
|
Mahesh.J wrote: the class
Which class? The one from the article I pointed you at?
Mahesh.J wrote: which is placed in the APP_Code folder
That's nice. Who put it there? You? Still doesn't answer the question I asked you; are you sure the XSLT processor can see the extension class?
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|