xml attribute problem and built in function or ( javascript )

S

surflorida

hello,

I have two problems have I been hacking on for awhile looking in books
and web:
- getting the correct value of EMPTY emelement value:

in my dtd I have

!DOCTYPE foo [
<!ELEMENT foo (bar*)>
<!ATTLIST foo name CDATA #REQUIRED>

in my .xsl I have no problem getting value of name by using:
<xsl:value-of select="/foo/@name"/>

But in my EMPTY element dtd
<!ELEMENT bar( foo2,number )>
<!ELEMENT foo2 EMPTY>
<!ATTLIST foo2 code (A|B|C|D|E) #REQUIRED>
<!ELEMENT number (#PCDATA)>

<xsl:value-of select="/foo/bar/foo2/@code"

But since their are many <bar></bar>
it only appears to the value for the first code in foo and displays
it for the rest, e.g .xml file
<bar>
<foo2 code="A"/>
</bar>
<bar>
<foo2 code="B"/>
</bar>


..xsl
<xsl:for-each select="foo/bar">
<xsl:value-of select="/foo/bar/foo2/@code"
</xsl:for-each>

will display "A" for both not "A" and "B".

where foo is the grandparent of foo2.


- along the same lines

<!ELEMENT number (#PCDATA)>

where number is a real number 2,4,9000, etc... in my .xml file.
is their a function where I can get pass the number to javascript
function
in my .xsl file

I try things like:

onload checknumber"( <xsl:value-of select="number"/> )";

but cannot get the number.

<xsl:value-of select="number"/> alone will display the correct number.

thanks in advance.
 
D

David Carlisle

<xsl:value-of select="/foo/bar/foo2/@code"

select="/foo/bar/foo2/@code2 selects a node set of all the code
attribute nodes of all the foo2 grandchildren of the bar children of
the top level foo element.

xsl:value of is defined to return the string value of the first node
(only) in its selected node set.

Your DTD fragments don't really have any bearing on this, and you
haven't said what transform you are trying to do so it's hard to
suggest what code you should use, something like
<xsl:for-each select="/foo/bar/foo2/@code">
<xsl:value-of select="."/>,
</xsl:for-each>
will make a comma separated list for example.


I try things like:

onload checknumber"( <xsl:value-of select="number"/> )";


You didn't show it but I guess that was inside an attribute. XSLT files
have to be well formed XML and you can't have a < in an XML attribute
value. Probably you want
"({number})"

See any xslt tutorial on attribute value templates for details of the {}
notation.

David
 

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

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,150
Latest member
MakersCBDReviews
Top