Newbie: Help with xml and xsl stylesheet

Discussion in 'XML' started by no spam, Feb 25, 2004.

  1. no spam

    no spam Guest

    Hi,

    I am trying to build reusable templates for user input forms, and then
    just use XSL to generate the forms...but I cannot get my xsl to match
    any templates, and the output is fine.

    here is my xml in full:
    >>>> XML FILE >>>

    <?xml version="1.0"?>
    <?xml-stylesheet type="text/xsl"
    href="http://lxsjfk1is1/ssrinterface/devutils/myform.xsl"?>

    <fields>
    <field>
    <name>lAccount_Num</name>
    <caption>Account Number:</caption>
    <type>label</type>
    <size></size>
    <style>LEFT: 17px; WIDTH: 112px; POSITION: absolute; TOP: 13px;
    HEIGHT: 18px</style>
    <FOR>tAccount_Num</FOR>
    <maxLength></maxLength>
    <value/>
    </field>
    <field>
    <name>tAccount_Num</name>
    <caption></caption>
    <type>Text</type>
    <size></size>
    <style>FONT-SIZE: xx-small; LEFT: 127px; WIDTH: 165px; POSITION:
    absolute; TOP: 13px; HEIGHT: 18px</style>
    <FOR></FOR>
    <maxLength>15</maxLength>
    <value/>
    </field>
    <field>
    <name>tCRY</name>
    <caption></caption>
    <type>Text</type>
    <size></size>
    <style>FONT-SIZE: xx-small; LEFT: 400px; WIDTH: 50px; POSITION:
    absolute; TOP: 13px; HEIGHT: 18px</style>
    <FOR></FOR>
    <maxLength>3</maxLength>
    <value/>
    </field>
    <field>
    <name>lCRY</name>
    <caption>Currency:</caption>
    <type>label</type>
    <size></size>
    <style>LEFT: 330px; WIDTH: 120px; POSITION: absolute; TOP: 13px;
    HEIGHT: 18px</style>
    <FOR>tCRY</FOR>
    <maxLength>3</maxLength>
    <value/>
    </field>
    <field>
    <name>lAccount_Name</name>
    <caption>Account Name:</caption>
    <type>label</type>
    <size></size>
    <style>LEFT: 17px; WIDTH: 108px; POSITION: absolute; TOP: 40px;
    HEIGHT: 18px</style>
    <FOR>tAccount_Num</FOR>
    <maxLength></maxLength>
    <value/>
    </field>
    <field>
    <name>tAccount_Name</name>
    <caption></caption>
    <type>Text</type>
    <size></size>
    <style>FONT-SIZE: xx-small; LEFT: 127px; WIDTH: 325px; POSITION:
    absolute; TOP: 40px; HEIGHT: 18px</style>
    <FOR></FOR>
    <maxLength>75</maxLength>
    <value/>
    </field>
    <field>
    <name>lbranch_code</name>
    <caption>Branch Code:</caption>
    <type>label</type>
    <size></size>
    <style>LEFT: 17px; WIDTH: 112px; POSITION: absolute; TOP: 80px;
    HEIGHT: 18px</style>
    <FOR>tbranch_code</FOR>
    <maxLength></maxLength>
    <value/>
    </field>
    <field>
    <name>tbranch_code</name>
    <caption>Branch Code</caption>
    <type>Text</type>
    <size></size>
    <style>FONT-SIZE: xx-small; LEFT: 127px; WIDTH: 135px; POSITION:
    absolute; TOP: 80px; HEIGHT: 18px</style>
    <FOR></FOR>
    <maxLength>8</maxLength>
    <value/>
    </field>
    <field>
    <name>lEnabled</name>
    <caption>Enabled:</caption>
    <type>label</type>
    <size></size>
    <style>LEFT: 330px; WIDTH: 120px; POSITION: absolute; TOP: 80px;
    HEIGHT: 18px</style>
    <FOR>chEnable</FOR>
    <maxLength></maxLength>
    <value/>
    </field>

    <field>
    <name>chEnable</name>
    <caption></caption>
    <type>Checkbox</type>
    <size></size>
    <style>LEFT: 402px; WIDTH: 16px; POSITION: absolute; TOP: 80px;
    HEIGHT: 22px</style>
    <FOR></FOR>
    <maxLength></maxLength>
    <value/>
    </field>
    </fields>
    </xml>

    <<< END OF XML <<<

    and here is my XSL file in full:

    >>> XSL Stylesheet >>>


    <?xml version="1.0"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">

    <xsl:template match="field">

    <xsl:choose>

    <xsl:when match=".[type='Text']">
    <input type="text">
    <xsl:attribute name="name">
    <xsl:value-of select="name"/>
    </xsl:attribute>

    <xsl:if test=".[width!='']">
    <xsl:attribute name="maxlength">
    <xsl:value-of select="width"/>
    </xsl:attribute>
    </xsl:if>

    </input>
    </xsl:when>

    <xsl:when match=".[type='label']">

    <label>
    <xsl:attribute name="name">
    <xsl:value-of select="name"/>
    </xsl:attribute>

    <xsl:attribute for="FOR">
    <xsl:value-of select="for"/>
    </xsl:attribute>

    <xsl:attribute for="style">
    <xsl:value-of select="style"/>
    </xsl:attribute>

    <xsl:if test=".[maxlength!='']">
    <xsl:attribute name="maxlength">
    <xsl:value-of select="maxlength"/>
    </xsl:attribute>
    </xsl:if>

    <xsl:if test=".[size!='']">
    <xsl:attribute name="size">
    <xsl:value-of select="size"/>
    </xsl:attribute>
    </xsl:if>

    <!-- CAPTION for Label -->
    <xsl:value-of select="caption"/>
    </label>

    </xsl:when>

    <xsl:when match=".[type='Checkbox']">
    <input type="checkbox">
    <xsl:attribute name="name">
    <xsl:value-of select="name"/>
    </xsl:attribute>

    <xsl:attribute for="style">
    <xsl:value-of select="style"/>
    </xsl:attribute>

    </input>
    </xsl:when>

    </xsl:choose>

    </xsl:template>
    </xsl:stylesheet>

    <<<< END OF XSL <<<<

    both validate fine using MS XML4 Processor...using IE 6 on Windows 2000.

    please point me in the right direction, thanks

    Philip


    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    no spam, Feb 25, 2004
    #1
    1. Advertising

  2. In article <403c6f69$0$198$>,
    no spam <> wrote:

    % I am trying to build reusable templates for user input forms, and then
    % just use XSL to generate the forms...but I cannot get my xsl to match
    % any templates, and the output is fine.

    If the output is fine, what is the trouble?

    % <xsl:when match=".[type='Text']">

    This should be

    <xsl:when test=".[type='Text']">

    or you could have

    <xsl:when test="type='Text'">

    I would be inclined to create several small templates rather than one
    template with a choose in it

    <xsl:template match="field[type='Text']">
    <input type="text" name="{name}">

    <xsl:if test="width!=''">
    <xsl:attribute name="maxlength">
    <xsl:value-of select="width"/>
    </xsl:attribute>
    </xsl:if>

    </input>
    </xsl:template>


    --

    Patrick TJ McPhee
    East York Canada
     
    Patrick TJ McPhee, Feb 25, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steven An
    Replies:
    1
    Views:
    512
    Martin Honnen
    Nov 23, 2004
  2. Thomas Sommer
    Replies:
    0
    Views:
    434
    Thomas Sommer
    Nov 25, 2004
  3. MC
    Replies:
    1
    Views:
    7,302
    David Carlisle
    Mar 24, 2005
  4. David Blickstein
    Replies:
    3
    Views:
    1,055
    David Blickstein
    Aug 2, 2005
  5. Replies:
    0
    Views:
    546
Loading...

Share This Page