|
next
|
 Subject: Xquery How to Author: (Deleted User) Date: 15 Nov 2007 03:32 PM
|
Hi Ram,
unfortunately none of the XQuery processors that shipped with Stylus Studio 2007 Release 2 had the capability of saving XML fragments to arbitrary URLs. So, if you have to solve your problem now, you will have to switch to XSLT 2.0 and Saxon, using this sample stylesheet:
<?xml version='1.0'?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:for-each select="collection('file:///C:/testcase?select=file*.xml;recurse=no')">
<xsl:variable name="input_xml" select="."/>
<xsl:variable name="filename_with_ext" select="tokenize(document-uri($input_xml), '/')[last()]"/>
<xsl:variable name="url" select="concat('file:///C:/testcase/Out/',replace($filename_with_ext,'^file(.*)','output$1'))"/>
<xsl:result-document method="xml" href="{$url}" indent="yes">
<xsl:element name="{substring-before($filename_with_ext, '.')}">
<xsl:element name="{$input_xml/DataObject/@SuperClass}"/>
<xsl:for-each select="$input_xml/DataObject/Attributes/Attribute">
<xsl:element name="{@Name}">
<xsl:value-of select="concat(DataType/@DataType,'(',DataType/@Size,')')"/>
</xsl:element>
</xsl:for-each>
</xsl:element>
</xsl:result-document>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Hope this helps,
Alberto
|
top
|
 Subject: Xquery How to Author: (Deleted User) Date: 16 Nov 2007 02:28 AM Originally Posted: 16 Nov 2007 02:29 AM
|
This is the solution using DataDirect XQuery 3.1
for $input_xml in collection("file:///C:/testcase?select=file*.xml;recurse=no")
let $filename_with_ext := tokenize(fn:document-uri($input_xml), "/")[last()]
let $url := concat("file:///C:/testcase/Out/",replace($filename_with_ext,'^file(.*)','output$1'))
let $xml :=(
element {substring-before($filename_with_ext, ".")}
{
element {$input_xml/DataObject/@SuperClass}{},
for $attribute in $input_xml/DataObject/Attributes/Attribute
return
element {$attribute/@Name}
{
concat($attribute/DataType/@DataType,"(",$attribute/DataType/@Size,")")
}
}
)
return ddtek:serialize-to-url($xml, $url, "")
Alberto
|
|
|
|