perstam

Hi,

Sorry this is going to be a long post but I felt it necessary to include source code.

Here's a very small portion of my xml document:

< xml version="1.0" >
<xtvd>
<stations>
<station id="10436">
<callSign>KERA</callSign>
<name>KERA</name>
<affiliate>PBS Affiliate</affiliate>
</station>
<station id="10830">
<callSign>KXAS</callSign>
<name>KXAS</name>
<affiliate>NBC Affiliate</affiliate>
</station>
<station id="16123">
<callSign>TVLAND</callSign>
<name>TV Land</name>
<affiliate>Satellite</affiliate>
</station>
<station id="11430">
<callSign>WFAA</callSign>
<name>WFAA</name>
<affiliate>ABC Affiliate</affiliate>
</station>
</stations>
<lineups>
<lineup id="TX42457:-" name="Time Warner Cable" location="Commerce" type="Cable" postalCode="75428">
<map station="10436" channel="13" />
<map station="10830" channel="5" />
<map station="11430" channel="8" />
<map station="16123" channel="44" from="2004-12-06" />
</lineup>
</lineups>
<schedules>
<schedule program="EP0019520018" station="16123" time="2006-12-18T09:00:00Z" duration="PT00H30M" tvRating="TV-G" />
<schedule program="EP0019520019" station="16123" time="2006-12-18T22:00:00Z" duration="PT00H30M" tvRating="TV-G" />
<schedule program="EP0019520020" station="16123" time="2006-12-18T16:30:00Z" duration="PT00H30M" tvRating="TV-G" />
<schedule program="EP0019730339" station="16123" time="2006-12-18T13:00:00Z" duration="PT01H00M" tvRating="TV-G" closeCaptioned="true" />
</schedules>

<programs>
<program id="EP0019520018">
<title>Green Acres</title>
<subtitle>Oh, Promise Me</subtitle>
<description>An error may mean Oliver and Lisa are not married.</description>
<showType>Series</showType>
<series>SH001952</series>
<originalAirDate>1969-03-05</originalAirDate>
</program>
<program id="EP0019520019">
<title>Green Acres</title>
<subtitle>Eb Uses His Ingenuity</subtitle>
<description>Eb involves the Douglases in a moneymaking scheme.</description>
<showType>Series</showType>
<series>SH001952</series>
<originalAirDate>1969-03-12</originalAirDate>
</program>
<program id="EP0019520020">
<title>Green Acres</title>
<subtitle>The Old Trunk</subtitle>
<description>The Douglases find a romantic tale in an old trunk.</description>
<showType>Series</showType>
<series>SH001952</series>
<originalAirDate>1969-03-19</originalAirDate>
</program>
<program id="EP0019730339">
<title>Gunsmoke</title>
<subtitle>Tatum</subtitle>
<description>Bitter townspeople don't want an elderly gunfighter buried next to his wife in their cemetery.</description>
<showType>Series</showType>
<series>SH001973</series>
<originalAirDate>1972-11-13</originalAirDate>
</program>
</programs>

</xtvd>

And here's the XSLT code I wrote:

< xml version="1.0" encoding="UTF-8" >

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:key name="progid" match="programs/program" use="@id" />

<xsl:key name="schprogid" match="schedules/schedule" use="@program" />

<xsl:key name="lineupstationid" match="lineups/lineup/map" use="@station"/>

<xsl:key name="stationid" match="stations/station" use="@id"/>

<xsl:template match="/">

<xsl:for-each select="//programs/program">

<br></br> <br></br>

Title: <xsl:value-of select="title[.='Green Acres']"/>

<br></br>

SubTitle: <xsl:value-of select="subtitle" />

Description: <xsl:value-of select="description" />

Series: <xsl:value-of select="series" />

RunTime: <xsl:value-of select="runTime" />

OriginalAirDate: <xsl:value-of select="originalAirDate" />

<xsl:for-each select="key('schprogid', @id)">

Time: <xsl:value-of select="@time"/>

Duration: <xsl:value-of select="@duration"/>

Repeat: <xsl:value-of select="@repeat"/>

TVRating: <xsl:value-of select="@tvRating"/>

<xsl:for-each select="key('lineupstationid', @station)">

Channel: <xsl:value-of select="@channel"/>

</xsl:for-each>

<xsl:for-each select="key('stationid', @station)">

CallSign: <xsl:value-of select="callSign"/>

Name: <xsl:value-of select="name"/>

Affiliate: <xsl:value-of select="affiliate"/>

</xsl:for-each>

</xsl:for-each>

</xsl:for-each>

</xsl:template>

</xsl:stylesheet>

What happens is the html document I'm producing with XslCompiledTransform in my C# program displays each of the "Green Acres" with their detail information, then displays the "Gunsmoke" episode without a title.

What I want to do is use XPath select for my favorite shows and list the detailed information about each. How do I remove the "Gunsmoke" data from the output How do I search for a list of favorite program titles



Re: XML and the .NET Framework XSLT: search for specific nodes and nodes related to each

Dimitre_Novatchev - MSFT

> How do I remove the "Gunsmoke" data from the output

Replace:

<xsl:for-each select="//programs/program">

with:

<xsl:for-each select=
"//programs/program[title='Green Acres']">

> How do I search for a list of favorite program titles

Provide them as a parameter to the XSLT transformation -- either a comma separated list or a separate tree (xml document). To do this, read about the XsltArgumentList class.

Cheers,
Dimitre Novatchev





Re: XML and the .NET Framework XSLT: search for specific nodes and nodes related to each

Dimitre_Novatchev - MSFT

> How do I remove the "Gunsmoke" data from the output

Replace:

<xsl:for-each select="//programs/program">

with:

<xsl:for-each select=
"//programs/program[title='Green Acres']">

> How do I search for a list of favorite program titles

Provide them as a parameter to the XSLT transformation -- either a comma separated list or a separate tree (xml document). To do this, read about the XsltArgumentList class.

Cheers,
Dimitre Novatchev





Re: XML and the .NET Framework XSLT: search for specific nodes and nodes related to each

perstam

Thanks so much for being patient with me.

I had tried this technique, but left the period between the [ and the = sign. Syntax makes such a difference! And, of course, I got no error message. I've been programming computers for 36 years and it sure is nice to have a compiler around to find those kinds of syntax errors. This is the reason I hate interpreted languages like Java script, HTML, XML, & XSLT. The interpreter in the browser is just not very helpful from a development perspective as compared to good old compilers.

I'll do some research on the XsltArgumentList class and see if I can get it to work, in the meantime I have one more question.

The time and duration (and the original air date to some extent) are coded in the original XML document in a not very user friendly manner. Are there any string functions I can use to clean these fields up Obviously I could post-process the XSLT output and use C# to do it, but that doesn't seem like a very clean approach.





Re: XML and the .NET Framework XSLT: search for specific nodes and nodes related to each

Dimitre_Novatchev - MSFT

The standard XPath 1.0 functions:

substring()

substring-after()

substring-before()

starts-with()

string-length()

translate()

are the usual ones used in "parsing" a date encoded as a string.

It may be useful to look up the XSLT FAQ of Dave Pawson.

Cheers,
Dimitre Novatchev





Re: XML and the .NET Framework XSLT: search for specific nodes and nodes related to each

Martin Honnen

perstam wrote:

I had tried this technique, but left the period between the [ and the = sign. Syntax makes such a difference! And, of course, I got no error message. I've been programming computers for 36 years and it sure is nice to have a compiler around to find those kinds of syntax errors. This is the reason I hate interpreted languages like Java script, HTML, XML, & XSLT. The interpreter in the browser is just not very helpful from a development perspective as compared to good old compilers.

The XSLT processor will tell you about syntax errors but doing //programs/program[. = 'Green Acres'] is not a syntax error.

perstam wrote:

The time and duration (and the original air date to some extent) are coded in the original XML document in a not very user friendly manner. Are there any string functions I can use to clean these fields up Obviously I could post-process the XSLT output and use C# to do it, but that doesn't seem like a very clean approach.

XslCompiledTransform supports two extension functions ms:format-date and ms:format-time in the namespace urn:schemas-microsoft-com:xslt, here is an example

<xsl:template match="schedule">

<xsl:value-of select="ms:format-date(@time, 'MMMM d yyyy', 'en-US')"/>

</xsl:template>

Documentation is on MSDN.






Re: XML and the .NET Framework XSLT: search for specific nodes and nodes related to each

Dimitre_Novatchev - MSFT

perstam wrote:

Thanks so much for being patient with me.

I had tried this technique, but left the period between the [ and the = sign.

Could you, please, provide a complete (but the minimal possible example) of not getting a syntax error If reproed, this will constitute a bug in the current implementation.

Cheers,
Dimitre Novatchev





Re: XML and the .NET Framework XSLT: search for specific nodes and nodes related to each

perstam

OK.

When I code

<xsl:for-each select="//programs/program/title[.='Green Acres']">

Title: <xsl:value-of select="title"/>

The transformed HTML file looks like this:

Title:
SubTitle: Description: Series: RunTime: OriginalAirDate:

Title:
SubTitle: Description: Series: RunTime: OriginalAirDate:

Title:
SubTitle: Description: Series: RunTime: OriginalAirDate:

and I get no error message when this line executes in my C# program:

ct.Transform(@"..\..\xmltest.xml", @"..\..\TVSchedule.html");

On the other hand when I code like this:

<xsl:for-each select="//programs/program">

<br></br> <br></br>

Title: <xsl:value-of select="title[.='Green Acres']"/>

The transformed HTML file looks like this:

Title: Green Acres
SubTitle: Oh, Promise Me Description: An error may mean Oliver and Lisa are not married. Series: SH001952 RunTime: OriginalAirDate: 1969-03-05 Time: 2006-12-18T09:00:00Z Duration: PT00H30M Repeat: TVRating: TV-G Channel: 44 CallSign: TVLAND Name: TV Land Affiliate: Satellite

Title: Green Acres
SubTitle: Eb Uses His Ingenuity Description: Eb involves the Douglases in a moneymaking scheme. Series: SH001952 RunTime: OriginalAirDate: 1969-03-12 Time: 2006-12-18T22:00:00Z Duration: PT00H30M Repeat: TVRating: TV-G Channel: 44 CallSign: TVLAND Name: TV Land Affiliate: Satellite

Title: Green Acres
SubTitle: The Old Trunk Description: The Douglases find a romantic tale in an old trunk. Series: SH001952 RunTime: OriginalAirDate: 1969-03-19 Time: 2006-12-18T16:30:00Z Duration: PT00H30M Repeat: TVRating: TV-G Channel: 44 CallSign: TVLAND Name: TV Land Affiliate: Satellite

Title:
SubTitle: Tatum Description: Bitter townspeople don't want an elderly gunfighter buried next to his wife in their cemetery. Series: SH001973 RunTime: OriginalAirDate: 1972-11-13 Time: 2006-12-18T13:00:00Z Duration: PT01H00M Repeat: TVRating: TV-G Channel: 44 CallSign: TVLAND Name: TV Land Affiliate: Satellite

I get no error messages from either version of coding, just not the output I wanted.





Re: XML and the .NET Framework XSLT: search for specific nodes and nodes related to each

Dimitre_Novatchev - MSFT

perstam wrote:

OK.

When I code

<xsl:for-each select="//programs/program/title[.='Green Acres']">

Title: <xsl:value-of select="title"/>

The transformed HTML file looks like this:

Title:
SubTitle: Description: Series: RunTime: OriginalAirDate:

Title:
SubTitle: Description: Series: RunTime: OriginalAirDate:

Title:
SubTitle: Description: Series: RunTime: OriginalAirDate:

and I get no error message when this line executes in my C# program:

ct.Transform(@"..\..\xmltest.xml", @"..\..\TVSchedule.html");

There isn't any XPath syntax error.

The "select" attribute in:

Title: <xsl:value-of select="title"/>

doesn't select anything, because the current node is a "title" node and it doesn't have any "title" children. The same goes for selecting other elements, because they are not children of a "title", too.

perstam wrote:

On the other hand when I code like this:

<xsl:for-each select="//programs/program">

<br></br> <br></br>

Title: <xsl:value-of select="title[.='Green Acres']"/>

The transformed HTML file looks like this:

Title: Green Acres
SubTitle: Oh, Promise Me Description: An error may mean Oliver and Lisa are not married. Series: SH001952 RunTime: OriginalAirDate: 1969-03-05 Time: 2006-12-18T09:00:00Z Duration: PT00H30M Repeat: TVRating: TV-G Channel: 44 CallSign: TVLAND Name: TV Land Affiliate: Satellite

Title: Green Acres
SubTitle: Eb Uses His Ingenuity Description: Eb involves the Douglases in a moneymaking scheme. Series: SH001952 RunTime: OriginalAirDate: 1969-03-12 Time: 2006-12-18T22:00:00Z Duration: PT00H30M Repeat: TVRating: TV-G Channel: 44 CallSign: TVLAND Name: TV Land Affiliate: Satellite

Title: Green Acres
SubTitle: The Old Trunk Description: The Douglases find a romantic tale in an old trunk. Series: SH001952 RunTime: OriginalAirDate: 1969-03-19 Time: 2006-12-18T16:30:00Z Duration: PT00H30M Repeat: TVRating: TV-G Channel: 44 CallSign: TVLAND Name: TV Land Affiliate: Satellite

Title:
SubTitle: Tatum Description: Bitter townspeople don't want an elderly gunfighter buried next to his wife in their cemetery. Series: SH001973 RunTime: OriginalAirDate: 1972-11-13 Time: 2006-12-18T13:00:00Z Duration: PT01H00M Repeat: TVRating: TV-G Channel: 44 CallSign: TVLAND Name: TV Land Affiliate: Satellite

I get no error messages from either version of coding, just not the output I wanted.

What error message would you expect There is no syntax error and a language processor usually does not try to detect logical errors like the ones in your code.

A schema aware (SA) XSLT2.0 processor could detect such errors at compile time and issue warnings. An XSLT 1.0 processor or a basic (non-SA) XSLT2.0 processor doesn't know what the input xml document will be (whether a "title" element may have a "title" child or not) and cannot issue any warnings.

Cheers,
Dimitre Novatchev





Re: XML and the .NET Framework XSLT: search for specific nodes and nodes related to each

perstam

OK.

I've been given some good information to do some more work. I'll go off and do that and get back with you if I get stuck again.

Thanks!