Commit e710a6d0 authored by Jérôme Euzenat's avatar Jérôme Euzenat
Browse files

- implemented AddTag (and inclusion in Modtag)

- improved Flatten (less interaction with other transformations)
parent baac7777
/**
* $Id: AddTag.java,v 1.2 2003-01-16 13:37:41 triolet Exp $
* $Id: AddTag.java,v 1.3 2004-02-24 16:27:06 jerome Exp $
*
* Transmorpher
*
* Copyright (C) 2001-2002 Fluxmedia and INRIA Rhône-Alpes.
* Copyright (C) 2004 INRIA Rhône-Alpes.
*
* http://www.fluxmedia.fr - http://transmorpher.inrialpes.fr
*
......@@ -123,21 +124,14 @@ public class AddTag implements Rule {
System.out.println("/>");
}
//** THIS HAS NOT BEEN DEFINED */
/**
* Description of the Method
*
*@param file Description of the Parameter
*@exception IOException Description of the Exception
*/
public void generateXSLTCode(Writer file) throws IOException {
file.writeln(2, "<!-- Removing attributes " + match + " -->");
file.write(2, "<xsl:template match=\"");
if (context != null) {
file.write(context + "/");
}
file.writeln("@" + match + "\"/>");
file.writeln("");
public void generateXSLTCode(Writer file) throws TMException {
throw new TMException("[AddTag]generateXSLTCode: not outside ModTag");
}
/**
......@@ -146,8 +140,10 @@ public class AddTag implements Rule {
*@param file Description of the Parameter
*@exception TMException Description of the Exception
*/
public void generateInsideXSLTCode(Writer file) throws TMException {
throw new TMException("[AddTag]generateInsideXSLTCode: not implemented yet");
public void generateInsideXSLTCode(Writer file) throws IOException {
file.writeln(2, "<!-- Adding element " + match + " -->");
file.writeln("<" + match + "/>");
file.writeln("");
}
}
......
/**
* $Id: Flatten.java,v 1.4 2004-02-24 15:08:00 jerome Exp $
* $Id: Flatten.java,v 1.5 2004-02-24 16:27:06 jerome Exp $
*
* Transmorpher
*
......@@ -121,9 +121,7 @@ public class Flatten implements Rule {
file.writeln(2, "</xsl:template>");
file.writeln("");
file.writeln(2, "<xsl:template match=\"*|@*|text()\" mode=\"inside" + match + "\">");
file.writeln(4, "<xsl:copy>");
file.writeln(6, "<xsl:apply-templates select=\"*|@*|text()\"/>");
file.writeln(4, "</xsl:copy>");
file.writeln(4, "<xsl:apply-templates select=\".\"/>");
file.writeln(2, "</xsl:template>");
file.writeln("");
}
......
/**
* $Id: ModTag.java,v 1.4 2003-05-26 15:03:50 triolet Exp $
* $Id: ModTag.java,v 1.5 2004-02-24 16:27:06 jerome Exp $
*
* Transmorpher
*
* Copyright (C) 2001-2002 Fluxmedia and INRIA Rhône-Alpes.
* Copyright (C) 2004 INRIA Rhône-Alpes.
*
* http://www.fluxmedia.fr - http://transmorpher.inrialpes.fr
*
......@@ -203,39 +204,39 @@ public class ModTag implements Rule {
*@exception IOException Description of the Exception
*/
public void generateXSLTCode(Writer file) throws TMException, IOException {
file.writeln(2, "<!-- Modifying element " + match + " -->");
file.write(2, "<xsl:template match=\"");
if (context != null) {
file.write(context + "/");
}
file.writeln(match + "\">");
if (target != null) {
file.write(4, "<" + target + " xsl:exclude-result-prefixes=\"regexp #default\">");
} else {
file.writeln(4, "<xsl:copy>");
}
for (int i = 0; i < rules.size(); i++) {
((Rule)rules.get(i)).generateInsideXSLTCode(file);
}
file.writeln(6, "<xsl:apply-templates select=\"*|@*|text()\"/>");
if (target != null) {
file.write(4, "</" + target + ">");
} else {
file.writeln(4, "</xsl:copy>");
}
file.writeln(2, "</xsl:template>");
file.writeln("");
for (int i = 0; i < rules.size(); i++) {
Rule r = (Rule)rules.get(i);
if ((r instanceof RemAtt) || (r instanceof MapAtt)) {
RemAtt rr = (RemAtt)r;
file.writeln(2, "<!-- Removing attributes " + rr.match
+ " on elements " + rr.context + " -->");
file.writeln(4, " <xsl:template match=\"" + rr.context + "/@" + rr.match + "\"/>");
file.writeln(2, "");
}
file.writeln(2, "<!-- Modifying element " + match + " -->");
file.write(2, "<xsl:template match=\"");
if (context != null) {
file.write(context + "/");
}
file.writeln(match + "\">");
if (target != null) {
file.write(4, "<" + target + " xsl:exclude-result-prefixes=\"regexp #default\">");
} else {
file.writeln(4, "<xsl:copy>");
}
for (int i = 0; i < rules.size(); i++) {
((Rule)rules.get(i)).generateInsideXSLTCode(file);
}
file.writeln(6, "<xsl:apply-templates select=\"*|@*|text()\"/>");
if (target != null) {
file.write(4, "</" + target + ">");
} else {
file.writeln(4, "</xsl:copy>");
}
file.writeln(2, "</xsl:template>");
file.writeln("");
for (int i = 0; i < rules.size(); i++) {
Rule r = (Rule)rules.get(i);
if ((r instanceof RemAtt) || (r instanceof MapAtt)) {
RemAtt rr = (RemAtt)r;
file.writeln(2, "<!-- Removing attributes " + rr.match
+ " on elements " + rr.context + " -->");
file.writeln(4, " <xsl:template match=\"" + rr.context + "/@" + rr.match + "\"/>");
file.writeln(2, "");
}
file.writeln("");
}
file.writeln("");
}
/**
......
/**
* $Id: RuleSetParser.java,v 1.4 2003-01-16 13:37:41 triolet Exp $
* $Id: RuleSetParser.java,v 1.5 2004-02-24 16:27:06 jerome Exp $
*
* Transmorpher
*
* Copyright (C) 2001-2002 Fluxmedia and INRIA Rhne-Alpes.
* Copyright (C) 2004 INRIA Rhne-Alpes.
*
* http://www.fluxmedia.fr - http://transmorpher.inrialpes.fr
*
......@@ -120,7 +121,11 @@ public class RuleSetParser extends FMParser{
((Ruleset)currentTransformation).addRule( (Rule)rule );
} else if (localName.equals("addtag")) {
rule = (Rule)new AddTag(atts.getValue("match"),atts.getValue("context"));
((Ruleset)currentTransformation).addRule( (Rule)rule );
if ( currentRule == null ) { //Not valid per DTD
((Ruleset)currentTransformation).addRule( (Rule)rule );
} else {
currentRule.addRule( (Rule)rule );
}
} else if (localName.equals("remtag")) {
rule = (Rule)new RemTag(atts.getValue("match"),atts.getValue("context"));
((Ruleset)currentTransformation).addRule( (Rule)rule );
......@@ -158,7 +163,7 @@ public class RuleSetParser extends FMParser{
if ( currentRule == null ) {
((Ruleset)currentTransformation).addRule( (Rule)rule );
} else {
currentRule.addRule( (Rule)rule );
currentRule.addRule( (Rule)rule );
}
} else if (localName.equals("resubst")) {
rule = (Rule)new RESubst(atts.getValue("match"),atts.getValue("context"),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment