[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Namespaces, params and Xalan

Subject: Namespaces, params and Xalan
From: Fraser Crichton <fraser.crichton@xxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 24 Sep 2004 14:05:22 +1200
transformer.setparameter namespace
Hi,

I'm a bit stumped by this - I'm using Xalan and trying to pass an xml fragment into my xsl as a parameter and then merge the fragment with my instance document.

What seems to happen is that the namespaces get stripped and I can't query the XML fragment once it's passed in as a param e.g xalan:nodeset($override)/cmn:MinorVersion/cmn:Number won't return anything from the fragment because the fully qualified name in the xpath query isn't in the fragment (I can however use local-name() to return something but that's a bit of a hack).

I saw something recently from Jenni Tennison that suggested that -

transformer.setParameter("TEXT", node);

effectively passes the node as a string and that this could cause problems?

Or is it just something stupid I'm missing?

I'm also looking at trying to get saxon to do the same thing with some problems.

Any help would be most welcome.

My fragment looks like this -

<?xml version="1.0" encoding="UTF-8"?>
<AccreditationModerationActionPlan
xmlns:cmn="http://www.nzqa.govt.nz/namespace/eqa/qual/commonV0"
xmlns:cfn="http://www.nzqa.govt.nz/namespace/eqa/qual/classificationV0"
xmlns:std="http://www.nzqa.govt.nz/namespace/eqa/qual/standardV0"
xmlns="http://www.nzqa.govt.nz/namespace/eqa/qual/accreditationModerationActionPlanV0">
 <cmn:Creator>Andy Mark Martin</cmn:Creator>
 <cmn:GenerationDate>22 Sep 2004</cmn:GenerationDate>
 <cmn:Item>
   <cmn:Number>9999</cmn:Number>
   <cmn:Status>99</cmn:Status>
 </cmn:Item>
 <cmn:Version>
   <cmn:Number>01</cmn:Number>
   <cmn:Status>01a</cmn:Status>
 </cmn:Version>
 <cmn:MinorVersion>
   <cmn:Number>777777</cmn:Number>
   <cmn:Status>02b</cmn:Status>
 </cmn:MinorVersion>
 <cmn:ClientId>0</cmn:ClientId>
 <cmn:StandardsSettingBody>
   <cmn:Reference>An ssbRef</cmn:Reference>
   <cmn:Name>Laura Martin</cmn:Name>
   <cmn:Number>2</cmn:Number>
 </cmn:StandardsSettingBody>
 <Title>A Title</Title>
 <Scope/>
</AccreditationModerationActionPlan>

The transformation code looks like this -


// We now have a juicy chunk of xml that we want to merge into the xml document.
TransformerFactory transformerFactory = TransformerFactory.newInstance();
String stylesheet = "C:/work/eQA/qual/src/xml/xslt/databaseMergeV0.xsl";
Transformer transformer = transformerFactory.newTransformer(new StreamSource(stylesheet));


DocumentBuilderFactory dbF = DocumentBuilderFactory.newInstance();
//Now I can use the namespaces in the DOM node
dbF.setNamespaceAware(true);


DocumentBuilder db = dbF.newDocumentBuilder();
File fragment = new File("C:/work/eQA/qual/src/xml/Examples/test-cases/fragment.xml");


Document doc = db.parse(fragment);

NodeList nodes = doc.getChildNodes();

FileWriter fileWriter = new FileWriter("c:/temp/xalanTest.xml");
FileReader fileReader = new FileReader("C:/work/eQA/qual/src/xml/Examples/test-cases/amapDraft.xml");
transformer.clearParameters();
transformer.setParameter("override", nodes.item(0));
transformer.transform(new StreamSource(fileReader), new StreamResult(fileWriter));
fileWriter.flush();


My XSL looks like this -

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns="http://www.nzqa.govt.nz/namespace/eqa/qual/accreditationModerationActionPlanV0"
xmlns:a="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"
xmlns:amap="http://www.nzqa.govt.nz/namespace/eqa/qual/accreditationModerationActionPlanV0"


xmlns:as="http://www.nzqa.govt.nz/namespace/eqa/qual/achievementStandardV0"
xmlns:anta="http://www.nzqa.govt.nz/namespace/eqa/qual/australianNationalTrainingAuthorityStandardV0"


xmlns:cfn="http://www.nzqa.govt.nz/namespace/eqa/qual/classificationV0"
xmlns:cmn="http://www.nzqa.govt.nz/namespace/eqa/qual/commonV0"
xmlns:doc="http://www.nzqa.govt.nz/xsl/documentation/1.0"
xmlns:i="urn:oasis:names:tc:ciq:xsdschema:xCIL:2.0"
xmlns:mas="http://www.nzqa.govt.nz/namespace/eqa/qual/mathAchievementStandardV0"
xmlns:n="urn:oasis:names:tc:ciq:xsdschema:xNL:2.0"
xmlns:r="urn:oasis:names:tc:ciq:xsdschema:xCRL:2.0"
xmlns:std="http://www.nzqa.govt.nz/namespace/eqa/qual/standardV0"
xmlns:txt="http://www.nzqa.govt.nz/namespace/eqa/qual/textV0"
xmlns:us="http://www.nzqa.govt.nz/namespace/eqa/qual/unitStandardV0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xalan="http://xml.apache.org/xalan"
exclude-result-prefixes="a amap as anta cfn cmn doc i mas n r std txt us xsi xalan"
version="1.0">


<!-- Common copying templates -->
<xsl:import href="copyV0.xsl"/>
<xsl:param name="override" />



<!-- NAMED TEMPLATES -->


   <xsl:template name="debug">
       <xsl:comment>Dynamically generated data</xsl:comment>
       <xsl:message>
           <xsl:text>Dynamically generating element named - {</xsl:text>
           <xsl:value-of select="namespace-uri()"/>
           <xsl:text>} </xsl:text>
           <xsl:value-of select="name()"/>
       </xsl:message>
   </xsl:template>

<!-- MATCHED TEMPLATES -->

<xsl:template match="/">
<xsl:apply-templates />
</xsl:template>


<xsl:template match="node()[(../. = /) and not(self::cmn:Comments)]">

<!-- Query $override as a node-set to see if the current element also exists
in the database generated fragement that has been passed in as a parameter-->
<xsl:variable name="fragment" select="xalan:nodeset($override)/node()/node()[name()=name(current())]"/>


<xsl:choose>
<xsl:when test="$fragment">
<xsl:call-template name="debug" />
<xsl:message>
**{<xsl:value-of select="namespace-uri($fragment)"/>}<xsl:value-of select="name($fragment)"/>
</xsl:message>
<xsl:copy-of select="$fragment" />
</xsl:when>
<xsl:otherwise>
<xsl:copy><xsl:apply-templates select="@*|node()"/></xsl:copy>
</xsl:otherwise>
</xsl:choose>
</xsl:template>


<xsl:template match="cmn:Comments">

<xsl:variable name="fragmentMinorVersionNumber" select="xalan:nodeset($override)/node()[./node()]/node()[local-name() = 'MinorVersion']/node()[local-name()='Number']" />

<xsl:copy>
<xsl:if test="not(cmn:Comment[@MinorVersionNumber = $fragmentMinorVersionNumber])">
<xsl:call-template name="debug" />
<xsl:message>
comment frag <xsl:value-of select="$fragmentMinorVersionNumber"/>
</xsl:message>
<cmn:Comment MinorVersionNumber="{$fragmentMinorVersionNumber}" />
</xsl:if>
<xsl:apply-templates select="@*|cmn:Comment">
<xsl:sort order="descending" select="@MinorVersionNumber" />
</xsl:apply-templates>
</xsl:copy>
</xsl:template>


</xsl:stylesheet>



--
Fraser Crichton
Web Developer
SolNet Solutions Limited
L12, SolNet House, 70 The Terrace
PO Box 397, Wellington, Aotearoa / New Zealand
www.solnetsolutions.co.nz <http://www.solnetsolutions.co.nz>
DDI: 04-462-5078
Mob: 027-278-3392
Fax: 04-462-5011
email: fraser.crichton@xxxxxxxxxxxxxxxxxxxxx <mailto:fraser.crichton@xxxxxxxxxxxxxxxxxxxxx>
--
Fraser Crichton
Web Developer
SolNet Solutions Limited
L12, SolNet House, 70 The Terrace
PO Box 397, Wellington, Aotearoa / New Zealand
www.solnetsolutions.co.nz <http://www.solnetsolutions.co.nz>
DDI: 04-462-5078
Mob: 027-278-3392
Fax: 04-462-5011
email: fraser.crichton@xxxxxxxxxxxxxxxxxxxxx <mailto:fraser.crichton@xxxxxxxxxxxxxxxxxxxxx>


Attention:
This email may contain information intended for the sole use of
the original recipient. Please respect this when sharing or
disclosing this email's contents with any third party. If you
believe you have received this email in error, please delete it
and notify the sender or postmaster@xxxxxxxxxxxxxxxxxxxxx as
soon as possible. The content of this email does not necessarily
reflect the views of SolNet Solutions Ltd.

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.