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=\""+xmlTagName+"='"+xslValue+"'\">" +
"<xsl:attribute name=\""+attributeName+"\">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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
>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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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=\""+xmlTagName+"='"+xslValue+"'\">" +
"<xsl:attribute name=\""+attributeName+"\">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
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.
>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
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
You shouldn't have to rewrite the NodeFactory.
Just register your NewInputTag with the PrototypicalNodeFactory.
OK, It works
thanks