Menu

HTML to XSL automatic transformation

Help
maxcube
2005-09-06
2013-04-27
  • maxcube

    maxcube - 2005-09-06

    I'm using HTMLParser to parse an html and automatically produce an xsl.
    So I need to modify tags and add some xsl specific tags.
    I implemented a NodeVisitor to achieve the goal

    so the option tag is changed from:
    <option value="m">Maschile</option>

    to:
    <option value="m">Maschile<xsl:if test="sesso='m'"><xsl:attribute name="selected">true</xsl:attribute></xsl:if></option>

    but it doesn't work with
    <input name="pezzo" type="radio" value="biopsia"/>

    the question is "WHY??"
    why with the option tag it works and doesn't work with the input tag?

    I'm attaching the code I applyed to the above tags
        protected Tag tagDecorator(Tag t, String attributeName, String xmlTagName, String xslValue)
        {
          t.removeAttribute(attributeName);
          NodeList childs = t.getChildren();
          try
          {
            Parser p = new Parser( new Lexer(
              "<xsl:if test=\&quot;"+xmlTagName+"='"+xslValue+"'\&quot;>" +
                "<xsl:attribute name=\&quot;"+attributeName+"\&quot;>true</xsl:attribute>" +
              "</xsl:if>"
            ) );

            NodeIterator ni = p.elements();
            while (ni.hasMoreNodes())
            {
              Node n = ni.nextNode();
              n.setParent(t);
              if (childs == null)
              {
                childs = new NodeList();
              }
              childs.add(n);
            }
            t.setChildren(childs);
          }
          catch (Exception ex)
          {
            ex.printStackTrace();
          }
          return t;
        }

    [hope the message can be read]
    thanks for any help!!
    bye

     
    • Derrick Oswald

      Derrick Oswald - 2005-09-06

      Which part doesn't work? The removal of the attribute, or the adding of the children to the list?

      The difference I notice is the second case is an XML ending tag which has no children (so it seems).

      case 1: <tag ... >children</tag>
      case 2: <tag ... />

      Perhaps you need to turn off the XML ending:
         tag.setEmptyXmlTag (false);
      and then add an end tag:
         tag.setEndTag (new Tag("/input"));

      Or perhaps you want to be editing the attribute list instead of the children.

       
    • maxcube

      maxcube - 2005-09-06

      >Which part doesn't work?
      method tagDecorator doesn't add childs to the input tag, while it works with the option tag!!

      it doesn't work with any of these instances of the input tag:
      <input name="pezzo" type="radio" value="sample1" >popo</input>
      <input name="pezzo" type="radio" value="sample2"/>
      <input name="pezzo" type="radio" value="sample3">

      thanks

       
    • maxcube

      maxcube - 2005-09-06

      I have found something!

      The difference is that
      InputTag hinerits from TagNode and
      OptionTag hinerits from CompositeTag
      and only the second take care about the childs.

      Now I'm triing to use a rewrited NodeFactory to instance a rewrited InputTag

      better ideas?

      thanks

       
      • Derrick Oswald

        Derrick Oswald - 2005-09-06

        You shouldn't have to rewrite the NodeFactory.
        Just register your NewInputTag with the PrototypicalNodeFactory.

         
    • maxcube

      maxcube - 2005-09-07

      OK, It works

      thanks

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.