xsl-list
[Top] [All Lists]

getting node type in xsl

2004-09-07 08:14:33
Hi people,

I am currently trying to make an asp.net based xml editor using this
xslt (it's just at a very beginning)

<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet
 version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
  <xsl:output
   method="xml"
   indent="yes"
   encoding="UTF-8"
   omit-xml-declaration="yes" />

  <xsl:template
   match="/">
    <html>
      <head>
        <title>XML Editor</title>

<style xml:space="preserve">
               * {font-family: sans-serif; font-size: small}
               fieldset {margin: 5px 5px 5px 30px; padding: 5px;}

</style>
      </head>

      <form>
        <xsl:apply-templates />
      </form>
    </html>
  </xsl:template>

  <xsl:template
   match="node()">
    <fieldset>
      <legend>
        <xsl:value-of
         select="local-name()" />
      </legend>

      <xsl:apply-templates
       select="@*" />

      <xsl:if
       test="./text()!=''">
        <input
         type="Text">
          <xsl:attribute
           name="value">
            <xsl:value-of
             select="./text()" />
          </xsl:attribute>
        </input>
      </xsl:if>

      <xsl:apply-templates
       select="*" />
    </fieldset>
  </xsl:template>

  <xsl:template
   match="@*">
    <xsl:variable
     name="id"
     select="generate-id()" />

    <div>
      <label
       for="{$id}">Attribute
      <xsl:value-of
       select="local-name()" />
      </label>

      <input
       type="Text"
       name="{$id}"
       id="{$id}">
        <xsl:attribute
         name="value">
          <xsl:value-of
           select="current()" />
        </xsl:attribute>
      </input>
    </div>
  </xsl:template>
</xsl:stylesheet>

this works as intended. Now, to provide the right controls (calendar
control for date, radio for enum...), I have two questions:

1) how can I find out about the current node's type defined in the
data document's xsd schema?
2) how can I give a node a unique id, that I can somehow reuse to
programmatically alter it's value (some serialization of the absolute
xPath using something else than the "/" and "[ ]" characters, like
"ID#animal-1#chicken-3#egg-5" for /animal[1]/chicken[3]/egg[5])?
generate-id() doesn't do this...

and there is a third! Am I reinventing the wheel for the nth time
here? I tried to google something up, but to no avail...

cheers and thanks for all the help from this great list!


-- 
Jan Limpens
http://www.limpens.com


<Prev in Thread] Current Thread [Next in Thread>