xsl check/selected radio buttons using php (data from mysql database)
I have an xml document that is transformed using XSL. I have a node that repeats many times that I made into radio buttons. I want to take the results in the database, and have the corresponding radio button values checked/selected. Here is the XSL code:
<xsl:for-each select="root/a/b">
<input type="radio" name="{autoincrementnumber}" value="{c[1]/@value}"/>
<xsl:value-of select="c[1]/ctext[@value='1']"/>
<input type="r开发者_Go百科adio" name="{autoincrementnumber}" value="{c[1]/@value}"/>
<xsl:value-of select="c[2]/ctext[@value='2']"/>
</xsl:for-each>
There are many nodes that are established via this for-each loop, so there are hundreds of radio buttons. How would I use php to pull from the database, and have it select/check the corresponding radio button?
database is an imploded string in one column:
1,2,1,1,2,1,2,1,2,1,2,1,2,1,21,....etc
XML document B=1 is selected for each node, so it appears many times.
...
<a>
<b value="1" >
<c value="1">Yes</c>
<c value="2">No</c>
<c value="3">Maybe</c>
</b>
...
FINAL RESULT: If 1 is pulled from database , then radio button value 1 is selected. if 2, then radio button 2 is selected. The checked radio buttons are all based on values in the database imploded as 1.2.1.4.1.2.4.3....etc
Here is working example of attribute usage and nasty XPath expression. Maybe it will help.
<input type="checkbox" name="{@name}" value="true">
<x:if test="translate($value, $uppercase, $smallcase)='true' or translate(@checked, $uppercase, $smallcase)='true'">
<x:attribute name="checked">checked</x:attribute>
</x:if>
</input>
Whole file is at asyncode.com/xslt/index.xsl - use it as a reference.
精彩评论