By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,962 Members | 1,998 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,962 IT Pros & Developers. It's quick & easy.

XSL problem: deeping a flat XML file

P: n/a
Jim
Greetings, all
Can anyone tell me what's wrong with the following XSL snippet? I'm getting absolutely no display on the following:

<xsl:template name="tier3">
<xsl:param name = "currentID" />
<xsl:for-each select="//Row">
<xsl:if test="Reports_To=$currentID"> <-------problem line
<p class="level3">
<xsl:value-of select="Unique_ID"/>&#xA0;&#xA0;<xsl:value-of select="Preferred_Name"/>
</p>
</xsl:if>
</xsl:for-each>

I've checked for typos, traced & printed variables, and all manner of things, but for some reason, line #4 (the "if" test) comes up empty, even though the strings in each are equivalent. I've checked it with DOM browser in Firefox, and I see only a string--no tags or "pollutants".
If I say <xsl:value-of select="Reports_To=$currentID">, it says falsefalsefalsefalse...
I've been struggling with this all day, and I'm comfortable with XSL, but not fluent enough for the exotic stuff. Can anybody tell me what the syntax problem is, and how to fix it? It couldn't be a datatype issue, could it?
I'm using .NET , and I've got MSXML 4.0 and 6.0 installed (for .NET 2.0)

Much appreciated.

--Jim
Mar 17 '06 #1
Share this Question
Share on Google+
7 Replies


P: n/a

Jim wrote:
<xsl:for-each select="//Row">
<xsl:if test="Reports_To=$currentID"> <-------problem line


try this

<xsl:for-each select="//Row">
[<xsl:value-of select="Reports_To">] "<xsl:value-of
select="@Reports_To">"
<xsl:if test="Reports_To=$currentID">

It won't fix it, but you should see something helpful appearing between
the [] or the ""
I can't tell what's wrong without seeing the input XML, but chances are
that "Reports_To" just isn't the right selector. Is the structure
this?
<Row><Reports_To>the-id-value</Reports_To></Row>
As style issues, then mixed case element names are a pain to work with
and so are "//*" selectors. Use /foo/bar/bat/wibble if you have to,
rather than //wibble

Mar 17 '06 #2

P: n/a
Show us what the XML for the Row element looks like? I suspect you
aren't testing what you think you're testing.

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Mar 17 '06 #3

P: n/a
Jim
Here's the structure.
<Root>
<Row>
<Unique_ID>ID2</Unique_ID>
<Address_Book_Title>Whatever Title</Address_Book_Title>
<Full_Name>Doe, John Doe</Full_Name>
<Org>SCorpOrg>
<Org_Detail>Marketing</Org_Detail>
<Preferred_Name>Johnny Doe</Preferred_Name>
<Reports_To>ID1</Reports_To>
</Row>
<Row>
....
</Row>
</Root>

I have tried /Root/Row/Reports_To[5] and <xsl:value-of select="$currentID">
and <xsl:value-of select="/Root/Row/Reports_To"> and they all work fine.
But when I try to put them in a test situation, somehow ID1 no longer equals
ID1.

Thanks.

--Jim

"Joe Kesselman" <ke************@comcast.net> wrote in message
news:7Z******************************@comcast.com. ..
Show us what the XML for the Row element looks like? I suspect you aren't
testing what you think you're testing.

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry

Mar 17 '06 #4

P: n/a
Are you really sure you're setting the parameter value correctly?

Here's my test driver. Running it on the document you gave us (after
fixing the typo) works just fine in Xylem...

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

<xsl:output method="xml" indent="yes" media-type="image/svg"/>

<xsl:template match="/">
<xsl:call-template name="tier3">
<xsl:with-param name="currentID">ID1</xsl:with-param>
</xsl:call-template>
</xsl:template>

<xsl:template name="tier3">
<xsl:param name = "currentID" />
<xsl:for-each select="//Row">
<xsl:if test="Reports_To=$currentID">
<p class="level3">
<xsl:value-of select="Unique_ID"/>&#xA0;&#xA0;<xsl:value-of
select="Preferred_Name"/>
</p>
</xsl:if>
</xsl:for-each>
</xsl:template>

</xsl:stylesheet>

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Mar 18 '06 #5

P: n/a
BTW, note that the line
<xsl:output method="xml" indent="yes" media-type="image/svg"/>


is unnecessary for this test; it was left over from a previous experiment.
--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Mar 18 '06 #6

P: n/a
Jim
Joe,
I found the problem: know thy data.
My info was originally in a complicated Visio org chart. When I exported
it to Excel, it flattened the heirarchy info, but used duplicate
"people"entries to maintain the heirarchy. I didn't realize the duplicate
thing was occuring. My code was fine, but I wasn't familiar enough with the
data to pick up on what was happening.
Once I realized what was going on, I added a check for the duplicate
tree thing, and presto.

Thanks for your help.

--Jim
"Joe Kesselman" <ke************@comcast.net> wrote in message
news:7r******************************@comcast.com. ..
Are you really sure you're setting the parameter value correctly?

Here's my test driver. Running it on the document you gave us (after
fixing the typo) works just fine in Xylem...

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

<xsl:output method="xml" indent="yes" media-type="image/svg"/>

<xsl:template match="/">
<xsl:call-template name="tier3">
<xsl:with-param name="currentID">ID1</xsl:with-param>
</xsl:call-template>
</xsl:template>

<xsl:template name="tier3">
<xsl:param name = "currentID" />
<xsl:for-each select="//Row">
<xsl:if test="Reports_To=$currentID">
<p class="level3">
<xsl:value-of select="Unique_ID"/>&#xA0;&#xA0;<xsl:value-of
select="Preferred_Name"/>
</p>
</xsl:if>
</xsl:for-each>
</xsl:template>

</xsl:stylesheet>

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry

Mar 19 '06 #7

P: n/a
Jim wrote:
I found the problem: know thy data.


Glad you found it. Been there, done that, which is why I always get a
bit suspicious when someone shows us only stylesheet or only data.

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Mar 19 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.