我正在使用oXygen XML编辑器,并定义了一系列XQuery转换。
问题是,截至目前,输入xml需要声明为:
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Iterator;
import java.util.HashSet;
import java.util.Set;
/**
* A simple model of a mail server. The server is able to receive
* mail items for storage, and deliver them to clients on demand.
*
* @author David J. Barnes and Michael Kölling
* @version 2011.07.31
*/
public class MailServer
{
// Storage for the arbitrary number of mail items to be stored
// on the server.
private HashMap<String, ArrayList<MailItem>> items;
/**
* Construct a mail server.
*/
public MailServer()
{
items = new HashMap<String, ArrayList<MailItem>>();
}
/**
* Return how many mail items are waiting for a user.
* @param who The user to check for.
* @return How many items are waiting.
*/
public int howManyMailItems(String who)
{
int count = 0;
for(String name : items.keySet())
{
if(who != null)
{
who = formatName(who);
}
if(items.containsKey(who))
{
count++;
}
}
return count;
}
/**
* Formats the name into lower case.
* @param who The user to check for.
*/
private static String formatName(String who)
{
if(who.length() > 0)
{
return who.toLowerCase();
}
return "";
}
/**
* Return the next mail item for a user or null if there
* are none.
* @param who The user requesting their next item.
* @return The user's next item.
*/
public MailItem getNextMailItem(String who)
{
if(who != null)
{
who = formatName(who);
}
ArrayList<MailItem> mails = items.get((who));
if(mails == null)
{
return null;
}
Iterator<MailItem> it = mails.iterator();
while(it.hasNext())
{
MailItem item = it.next();
if(item.getTo().equals(who))
{
it.remove();
return item;
}
}
return null;
}
/**
* Return the specified number of mail items for a user or
* null if there are none.
* @param who The user requesting their next item.
* @param howMany The number of mail items requested.
* @return The user's specified number of next items.
*/
public ArrayList<MailItem> getNextMailItems(String who, int howMany)
{
ArrayList<MailItem> itemsToReturn = new ArrayList<MailItem>();
if(who != null)
{
who = formatName(who);
}
ArrayList<MailItem> mails = items.get((who));
if(mails == null)
{
return null;
}
Iterator<MailItem> it = mails.iterator();
while(it.hasNext() && howMany > 0)
{
MailItem item = it.next();
it.remove();
itemsToReturn.add(item);
howMany--;
}
return itemsToReturn;
}
/**
* Add the given mail item to the message list.
* @param item The mail item to be stored on the server.
*/
public void post(MailItem item)
{
if(isSpam(item))
{
return;
}
String who = item.getTo();
ArrayList<MailItem> mails;
if(items.containsKey(who))
{
mails = items.get(who);
}
else
{
mails = new ArrayList<MailItem>();
items.put(who, mails);
}
mails.add(item);
}
/**
* Return true if the item is spam; otherwise return false.
* @param The mail item.
*/
private boolean isSpam(MailItem item)
{
if(item.getSubjectLine().contains("SPAM"))
{
return true;
}
if (item.getMessage().toLowerCase().contains("viagra"))
{
return true;
}
return false;
}
/**
* Iterates through the users, prints out each user name, and
* prints out all the emails associated with that user.
*/
public void printAllMessages()
{
for(String who : items.keySet())
{
ArrayList<MailItem> mails = items.get(who);
for(MailItem message : mails)
{
System.out.println(who + ": " + mails);
}
}
}
}
import java.util.ArrayList;
/**
* A class to model a simple email client. The client is run by a
* particular user, and sends and retrieves mail via a particular server.
*
* @author David J. Barnes and Michael Kölling
* @version 2011.07.31
*/
public class MailClient
{
// The server used for sending and receiving.
private MailServer server;
// The user running this client.
private String user;
private int howMany;
/**
* Create a mail client run by user and attached to the given server.
*/
public MailClient(MailServer server, String user)
{
this.server = server;
this.user = user;
}
/**
* Return the next mail item (if any) for this user.
*/
public MailItem getNextMailItem()
{
return server.getNextMailItem(user);
}
/**
* Return the specified number of mail items (if any)
* for this user.
*/
public ArrayList<MailItem> getNextMailItems(int howMany)
{
return server.getNextMailItems(user, howMany);
}
/**
* Print the next mail item (if any) for this user to the text
* terminal.
*/
public void printNextMailItem()
{
MailItem item = server.getNextMailItem(user);
if(item == null)
{
System.out.println("No new mail.");
}
else
{
item.print();
}
}
/**
* Send the given message to the given recipient via
* the attached mail server.
* @param to The intended recipient.
* @param message The text of the message to be sent.
*/
public void sendMailItem(String to, String subjectline, String message)
{
MailItem item = new MailItem(user, to, subjectline, message);
server.post(item);
}
}
/**
* A class to model a simple mail item. The item has sender and recipient
* addresses and a message string.
*
* @author David J. Barnes and Michael Kölling
* @version 2011.07.31
*/
public class MailItem
{
// The sender of the item.
private String from;
// The intended recipient.
private String to;
// The text of the message.
private String subjectline;
// The subject line of the message.
private String message;
/**
* Create a mail item from sender to the given recipient,
* containing the given message.
* @param from The sender of this item.
* @param to The intended recipient of this item.
* @param message The text of the message to be sent.
*/
public MailItem(String from, String to, String subjectline, String message)
{
this.from = from;
this.to = to;
this.subjectline = subjectline;
this.message = message;
}
/**
* @return The sender of this message.
*/
public String getFrom()
{
return from;
}
/**
* @return The intended recipient of this message.
*/
public String getTo()
{
return to.toLowerCase();
}
/**
* @return The subject line of this message.
*/
public String getSubjectLine()
{
return subjectline;
}
/**
* @return The text of the message.
*/
public String getMessage()
{
return message;
}
/**
* Print this mail message to the text terminal.
*/
public void print()
{
System.out.println("From: " + from);
System.out.println("To: " + to);
System.out.println("Subject Line: " + subjectline);
System.out.println("Message: " + message);
}
}
我想知道是否有某种方法用转换方案中定义的文件内容替换let $k := doc("path")
?
(即:在本例中为untitled.xml)
答案 0 :(得分:2)
尝试点击Parameters (0)
并添加值为URL
的新参数${currentFileURL}
。然后在你的脚本中prolog声明一个外部变量:
declare variable $URL external;
然后你应该能够引用doc($URL)
,如果XML URL在Oxygen中发生变化,它应该传递给你的XQuery脚本。