XSLT Scripting Question

W

wardellcastles

Is it possible to acccess a DOM object of the input XML inside of the
XSLT script?

I am planning to use <msxsl:script ..> with the C#.NET language.

What I need to do is at the beginning of the xslt to access a function
that will iterate over the XML and count elements within the XML, prior
to the elements themselves being iterated over in the XSLT.

For example from this input:

<Report>
<States>
<State>Florida</State>
<State>Georgia</Georgia>
</States>
</Report>

I need to produce a report like this:

The following 2 states are in the Southeastern US
Florida
Georgia

As you can see, to produce that first line, "The following 2 ..."
I need to count the number of <State> elements before they are actually
referenced in the XSLT.

Any ideas will be appreciated.
 
M

Martin Honnen

wardellcastles said:
Is it possible to acccess a DOM object of the input XML inside of the
XSLT script?

I am planning to use <msxsl:script ..> with the C#.NET language.

Not with .NET, no, there is an object model exposed but it is not the DOM.
What I need to do is at the beginning of the xslt to access a function
that will iterate over the XML and count elements within the XML, prior
to the elements themselves being iterated over in the XSLT.

For example from this input:

<Report>
<States>
<State>Florida</State>
<State>Georgia</Georgia>
</States>
</Report>

I need to produce a report like this:

The following 2 states are in the Southeastern US
Florida
Georgia

As you can see, to produce that first line, "The following 2 ..."
I need to count the number of <State> elements before they are actually
referenced in the XSLT.

How about
<xsl:variable name="states" select="/Report/States/State" />

<p>The following
<xsl:value-of select="count($states)" />
states are in the southeastern US
</p>
<ul>
<xsl:for-each select="$states">
<li><xsl:value-of select="." /></li>
</xsl:for-each>
</ul>

The variable is only there for efficiency, of course you can process the
nodes twice or several times if needed without using a variable.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,999
Messages
2,570,247
Members
46,844
Latest member
JudyGvh32

Latest Threads

Top