Xml – Text Attribute as value for another element

xmlxsltxslt-1.0

With the XML below, I would like to know how to get the value of text in the case_id node as an attribute for the hidden input tag in the xsl sheet below.
Is this possible?

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="data.xsl"?>
<NewDataSet>
<Cases>
<Case>
<case_id>30</case_id>
...
...
</Case>
</Cases>
</NewDataset>
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<input type="hidden" name="case_num" value="?"/>
</xsl:template>
</xsl:stylesheet>

Best Solution

Try this

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">
    <input type="hidden" name="case_num">
      <xsl:attribute name="value">
        <xsl:value-of select="/NewDataSet/Cases/Case/case_id/text()"/>
      </xsl:attribute>
    </input>
  </xsl:template>
</xsl:stylesheet>

or you can inline like this

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">
    <input type="hidden" name="case_num" value="{/NewDataSet/Cases/Case/case_id/text()}"/>
  </xsl:template>

Related Question