?
Solved

Outputting form elements using XSLT

Posted on 2004-11-16
6
Medium Priority
?
237 Views
Last Modified: 2013-11-19
I am trying to output a disabled checkbox using XSLT. If the value of the checkbox is "true", then the checkbox should be checked. I have tried two different methods, but the XML parser is not outputting the checkbox, or any form elements for that matter. I am using MSXML4. Is there another way to do it?

These are the two approaches that I have tried:

      <xsl:element name="input">
            <xsl:attribute name="type">checkbox</xsl:attribute>
            <xsl:attribute name="checked">true</xsl:attribute>
            <xsl:attribute name="disabled">true</xsl:attribute>
      </xsl:element>
      
      <input type="checkbox">
            <xsl:attribute name="disabled"/>
            <xsl:if test="Value = 'true'">
                  <xsl:attribute name="Checked"/>
            </xsl:if>
      </input>




0
Comment
Question by:mariita
  • 3
  • 3
6 Comments
 
LVL 15

Expert Comment

by:dualsoul
ID: 12598381
hm.....
ok, here is the my sample xml:
<?xml version="1.0" encoding="UTF-8"?>
<root>
      <Value>true</Value>
</root>

, and XSLT to output checkbox:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>      
      <xsl:template match="/">
            <input type="checkbox" disabled="disabled">          
                    <xsl:if test="/root/Value = 'true'">
                           <xsl:attribute name="checked">checked</xsl:attribute>
                    </xsl:if>
             </input>
      </xsl:template>
</xsl:stylesheet>


, it seems it works fine :)

if you still can't get idea how to make your xslt work, post your xml and xslt please.
0
 

Author Comment

by:mariita
ID: 12598629
It also works fine for me when I isolate it, but in the context of this particular XSLT stylesheet the parser seems to ignore the directive to output HTML form elements. Under what circumstances will the parser *not* output HTML? Is there a way to force the output?

M


0
 
LVL 15

Expert Comment

by:dualsoul
ID: 12602126
it would be better if you post your xml and xslt, it's hard to understand what is not working without seeing the sources.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:mariita
ID: 12605789
Here is the XSLT:

<?xml version="1.0" encoding="ISO-8859-1"?>
<?altova_samplexml C:\Documents and Settings\mamuchastegui\Desktop\Debug\ConfirmBillerInfoDES.xml?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
<xsl:output method="html" encoding="ISO-8859-1" indent="yes"/>
<xsl:variable name="FRM" select="PresentationData/PageSpecific/Form"/>
<xsl:variable name="vBillerDataRows">
<BillerDataRow>
<BillerLabel>Titulaire du compte&#160;:</BillerLabel>
<BillerValue>
<xsl:value-of select="$FRM/Field[@Name='AccountHolder']/Value"/>
</BillerValue>
</BillerDataRow>
<xsl:for-each select="$FRM/BillerParameters/Field[@IsComment = '0']">
<BillerDataRow>
<BillerLabel>
<xsl:value-of select="Prompt"/>
</BillerLabel>
<BillerValue>
<xsl:choose>
<!-- not checkbox, just display value -->
<xsl:when test="@Type != '2'">
<xsl:value-of select="Value"/>
</xsl:when>
<!-- checkbox, display disabled checkbox in appropriate state -->
<xsl:when test="@Type = '2'">
<input type="checkbox">
<xsl:attribute name="disabled"/>
<xsl:if test="Value = 'true'">
<xsl:attribute name="Checked"/>
</xsl:if>
</input>
</xsl:when>
</xsl:choose>
</BillerValue>
</BillerDataRow>
</xsl:for-each>
</xsl:variable>
<xsl:template match="/">
<html>
<head>
<style type="text/css">
.oddRow { background-color: #E9f5e9}
.evenRow { background-color: #FFFFFF}                  
.Cellule {font-family: Arial, Helvetica, sans-serif; font-size: 75%; font-weight: normal; color: #000000; padding-left: 2px; padding-top: 2px; padding-bottom: 2px}
</style>
</head>
<body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table>
<tbody>
<xsl:for-each select="msxsl:node-set($vBillerDataRows)/BillerDataRow">
<tr>
<xsl:attribute name="class"><xsl:choose><xsl:when test="position() mod 2 = 0">evenRow</xsl:when><xsl:otherwise>oddRow</xsl:otherwise></xsl:choose></xsl:attribute>
<td width="25%" class="Cellule">
<xsl:value-of select="BillerLabel"/>
</td>
<td width="75%" class="Cellule">
<xsl:value-of select="BillerValue"/>
</td>
</tr>
</xsl:for-each>
</tbody>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

-------------------------------------
And here is the XML data:

<?xml version="1.0" encoding="iso-8859-1"?>
<PresentationData Name="BillerInfo">
<PageSpecific>
<Form Name="BillerInfo">
<Field Name="AccountHolder" Type="text" Size="50" MaxLength="50" Mandatory="yes">
<Value>MME KNTUCT MPQBHSFBO</Value>
<Prompt>Account holder</Prompt>
<Message/>
</Field>
<BillerParameters Count="4">
<Field Name="AcctParam0" Type="3" Size="20" MaxLength="20" Mandatory="1" MaskID="1" MaskString="" UseMask="0" UseCalendar="0" IsComment="0" IsAlphanumeric="0">
<Value>100</Value>
<Prompt>Total dû</Prompt>
<Message/>
<Description>Saisissez les montants impayés totaux indiqués sur votre dernière facture. Exemple : 1000,99 ou 1000,99 lorsque le montant est négatif.</Description>
</Field>
<Field Name="AcctParam1" Type="5" Size="50" MaxLength="50" Mandatory="0" MaskID="1" MaskString="" UseMask="0" UseCalendar="0" IsComment="0" IsAlphanumeric="0">
<Value>maria@maria.com</Value>
<Prompt>Adresse de courriel</Prompt>
<Message/>
<Description>Si vous souhaitez recevoir un avis par courriel indiquant que vous pouvez consulter votre facture en ligne plutôt que de recevoir une facture papier, saisissez votre courriel.</Description>
</Field>
<Field Name="AcctParam2" Type="6" Size="10" MaxLength="10" Mandatory="1" MaskID="2" MaskString="" UseMask="1" UseCalendar="1" IsComment="0" IsAlphanumeric="0">
<Value>01-11-2004</Value>
<Prompt>Date Naissance</Prompt>
<Message/>
<Description>[Information du fournisseur pour le client. Format JJ-MM-AAAA]</Description>
</Field>
<Field Name="AcctParam3" Type="2" Size="10" MaxLength="10" Mandatory="0" MaskID="1" MaskString="" UseMask="0" UseCalendar="0" IsComment="0" IsAlphanumeric="0">
<Value>true</Value>
<Prompt>J'aime les factures en ligne.</Prompt>
<Message/>
<Description>[Indiquer ici si vous aimez l'idée des factures en ligne.]</Description>
</Field>
</BillerParameters>
</Form>
</PageSpecific>
</PresentationData>





0
 
LVL 15

Accepted Solution

by:
dualsoul earned 1500 total points
ID: 12614339
uh...the problem is due to using microsoft's extensions. This is not pure XSLT, you build your output in variable, and then using node-set() function to get resulting tree, somewhere here you loose the structure...hm....

i need to explore it a bit before i can answer. By the way why don't use pure XSLT solution?
0
 

Author Comment

by:mariita
ID: 12614655
You're right. I do need to use the node-set function, but I don't need to build the HTML in the node-set itself. I can do that later.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question