Xsl transformation of xml with wrong namespace

I have xml with wrong namespace:
<PAMStartedNotification xmlns="some site">
<tUser>PLVUSER</tUser>
</PAMStartedNotification>I need to leave this namespace and transform it.
As a result of transformation now I get
<tUser></tUser>
...I.e. XPath is not calculated properly.
If I leave out that namespace then everything is ok.
But I want to leave that namespace as it is.
I use the following code to transform xml:
Templates stylesheet = transformerFactory.newTemplates(new StreamSource(new File(fileName)));
Transformer processor = stylesheet.newTransformer();
java.io.StringWriter resultWriter = new java.io.StringWriter();
StreamResult streamResult = new StreamResult(resultWriter);
processor.transform(new StreamSource(new StringReader(xmlData)), streamResult);
transformedXML = resultWriter.getBuffer().toString();Any ideas how to do that(transform xml with wrong namespace)?
Edited by: prng on Dec 15, 2008 6:43 AM
Edited by: prng on Dec 15, 2008 6:45 AM

prng wrote:
Sorry.
Here is XPath I use to select tUser:
/PAMStartedNotification/tUser
Right. To start out, that selects a PAMStartedNotification element which is in no namespace. But yours isn't. It's in the default namespace, which doesn't have a prefix. You could try this XPath expression:
/*[local-name() = 'PAMStartedNotification']/*[local-name() = 'tUser'](Untested, might have mis-typings and so on.)

Similar Messages

  • Java transform problem - resulting XML has wrong namespace on imported Node

    I use Document.importNode(Node, String) to import a node from one document into another document. I want to preserve the namespace of the imported node. This works ok if the imported node specifies xmlns, even xmlns="". But if the imported node does not specify a namespace, I would expect the resulting serialized XML to have xmlns="". However, this is not the case. I use javax.xml.transform.Transformer when I serialize the XML. After the transform, the imported node has the namespace of the document it is imported into, which we do not want. So how do I get the imported node to serialize out with xmlns="", even if it's not specified in the source document? I am using javax.xml.transform.* and javax.xml.parsers.DocumentBuilder from Java 1.4.2.
    Example of XML that node is imported into (imported node replaces PayloadPlaceHolder):
    <?xml version="1.0" encoding="UTF-8"?>
    <Envelope envelopeVersion="0.0.0" classificationLevel="Unclassified" xmlns="http://disa.gcss.mil/XMLGateway/Envelope">
    <Header>
    <UID>GM0000001</UID>
    <DateTime>2006-12-05T16:11:50Z</DateTime>
    </Header>
    <Status reason="FAILED" lastTransactionID="9999999999" inReplyTo="ZZZ9999999999">
    <LastMessageUID>ZZZ9999999999</LastMessageUID>
    </Status>
    <Payload>
    <PayloadPlaceHolder>
    </PayloadPlaceHolder>
    </Payload>]
    </Envelope>
    Example of XML with null namespace, test_segment is imported node:
    <?xml version="1.0" encoding="UTF-8"?>
    <test_segment>
    <name>test</name>
    </test_segment>
    Example of result XML with imported node (test_segment):
    <?xml version="1.0" encoding="UTF-8"?>
    <Envelope classificationLevel="Unclassified" envelopeVersion="0.0.0" xmlns="http://disa.gcss.mil/XMLGateway/Envelope">
    <Header>
    <UID>GM0000001</UID>
    <DateTime>2006-12-05T16:11:50Z</DateTime>
    </Header>
    <Status inReplyTo="ZZZ9999999999" lastTransactionID="9999999999" reason="FAILED">
    <LastMessageUID>ZZZ9999999999</LastMessageUID>
    </Status>
    <Payload>
    <test_segment>
    <name>test</name>
    </test_segment>
    </Payload>
    </Envelope>
    Here is the code to build the documents and transform the XML:
         Document document = null;
    Document dataBlockDoc = null;
    ByteArrayInputStream inStream = new ByteArrayInputStream
    (StringUtils.getBytes(xml.toString()));
    try {
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware( true );
    DocumentBuilder parser = dbf.newDocumentBuilder();
    document =
    parser.parse(
    new InputSource(inStream ) );
    if (dataBlock != null) {
    inStream = new ByteArrayInputStream(StringUtils.getBytes(dataBlock));
    dataBlockDoc = parser.parse(
    new InputSource(inStream ) );
    Element root = document.getDocumentElement();
    Element payload = null;
    NodeList children = root.getChildNodes();
    //get Payload child from envelope document
    for (int i = 0; i < children.getLength(); i++) {
    if (children.item(i).getNodeName().equals("Payload")) {
    payload = (Element)children.item(i);
    break;
    //get the PayloadPlaceHolder
    Element payloadPlaceHolderElement = null;
    children = payload.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
    if (children.item(i).getNodeName().equals("PayloadPlaceHolder")) {
    payloadPlaceHolderElement = (Element)children.item(i);
    break;
    Node newPayload = null;
    if (dataBlockDoc != null) {
    Element dataBlockElement = dataBlockDoc.getDocumentElement();
    //make new Payload element to replace old (empty) Payload
    newPayload = document.importNode((Node) dataBlockElement, true);
    payload.replaceChild(newPayload, payloadPlaceHolderElement);
    else
    payload.removeChild(payloadPlaceHolderElement);
    TransformerFactory tf = TransformerFactory.newInstance();
    Transformer nullTransform = tf.newTransformer();
    ByteArrayOutputStream oStream = new ByteArrayOutputStream();
    nullTransform.transform(                    new DOMSource( document ),
         new StreamResult( oStream ) );
    xml = new StringBuffer(oStream.toString());
    Thanks in advance.

    It appears that the problem is that the DOM serializer implementation in JDK 1.4 is not properly handling namespaces. Does anyone know of a workaround or alternate serializers we could use to serialize a DOM tree? I also need it to work with XSLT.
    Thanks.

  • Transform the xml with ' and "

    HI,
    i am converting from one xml to anther xml using XSLT, in my output xml file &apos; values are replacing with ' symbols. i want &apos; values in my output xml file.
    my input xml file is
    <?xml version="1.0" encoding="UTF-8"?>
    <ARTICLE>
    <TITLE>A Sample Article123456&apos;123456&apos;</TITLE></ARTICLE>
    my xslt file is
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
    <xsl:output method="xml"/>
    <xsl:template match="/">
    <Message>
    <xsl:apply-templates/>
    </Message>
    </xsl:template>
    <xsl:template match="/ARTICLE/TITLE">
    <Sample><xsl:value-of select="/ARTICLE/TITLE" />
    </Sample>
    </xsl:template>
    </xsl:stylesheet>
    my java source code
    public class MessageGeneration
    public static void main(String []a)throws Exception
    Reader xmlSourceReader;
    Writer xmlResultWriter;
    xmlSourceReader = new InputStreamReader(new FileInputStream(
    "src/xml/message.xml"), "UTF-8");
    xmlResultWriter = new OutputStreamWriter(new FileOutputStream(
    "src/xml/outMessage.xml"), "UTF-8");
    TransformerFactory tranFactory = TransformerFactory.newInstance();
    Transformer transformer = tranFactory.newTransformer(source);
    StreamSource xmlSource1 = new StreamSource(xmlSourceReader);
    StreamResult xmlResult1 = new StreamResult(xmlResultWriter);
    transformer.transform(xmlSource1, xmlResult1);
    how can i get &apos; symbols in my out file.
    Thanks
    Dattu

    It isn't necessary to escape the apostrophes and quotes in the example you showed, although it isn't wrong to escape them either. Both are well-formed XML and they are equivalent. So that means you don't need to ask for them to be escaped, and therefore the XML philosophy implies you aren't allowed to ask for them to be escaped. Is there a particular reason you have to have them escaped?

  • DB Adapter on ESB with wrong namespace

    Hi,
    i have the following problem, i create for a stored procedure a service on the ESB - creation and execute on the ESB console (deploy via JDeveloper) without any problems - if i try to load from th service the WSDL into SOAPUI (for addional tests) - SOAPUI found no operation/binding. I found out that on the ESB - the ESB WSDL import the original WSDL with the wrong namespace.
    Example:
    WSDL of the ESB service:
    <?xml version = '1.0' encoding = 'UTF-8'?>
    <definitions targetNamespace="http://xmlns.oracle.com/pcbpel/adapter/db/Service_Order/"
    xmlns:ws="http://www.example.com/webservice" xmlns:plt="http://schemas.xmlsoap.org/ws/2003/05/partner-link/">
    ->    <import namespace="http://xmlns.oracle.com/pcbpel/adapter/db/" location="..../ESB_Projects/General_ServicAdapter_Select_Order/Service_Order.wsdl"/>
    <binding name="__esb_Service_Order_Service_Order_ptt" type="tns:Service_Order_ptt">
    Called WSDL:
    <definitions name="Service_Order"
    targetNamespace="http://xmlns.oracle.com/pcbpel/adapter/db/Service_Order/"
    xmlns="http://schemas.xmlsoap.org/wsdl/"
    xmlns:tns="http://xmlns.oracle.com/pcbpel/adapter/db/Service_Order/"
    The problem is i can not modify the namespace because the ESB WSDL (with the import) is generated by JDeveloper - any idea what is going wrong?
    Thanks and Best regards
    Thomas

    Hi,
    i have the following problem, i create for a stored procedure a service on the ESB - creation and execute on the ESB console (deploy via JDeveloper) without any problems - if i try to load from th service the WSDL into SOAPUI (for addional tests) - SOAPUI found no operation/binding. I found out that on the ESB - the ESB WSDL import the original WSDL with the wrong namespace.
    Example:
    WSDL of the ESB service:
    <?xml version = '1.0' encoding = 'UTF-8'?>
    <definitions targetNamespace="http://xmlns.oracle.com/pcbpel/adapter/db/Service_Order/"
    xmlns:ws="http://www.example.com/webservice" xmlns:plt="http://schemas.xmlsoap.org/ws/2003/05/partner-link/">
    ->    <import namespace="http://xmlns.oracle.com/pcbpel/adapter/db/" location="..../ESB_Projects/General_ServicAdapter_Select_Order/Service_Order.wsdl"/>
    <binding name="__esb_Service_Order_Service_Order_ptt" type="tns:Service_Order_ptt">
    Called WSDL:
    <definitions name="Service_Order"
    targetNamespace="http://xmlns.oracle.com/pcbpel/adapter/db/Service_Order/"
    xmlns="http://schemas.xmlsoap.org/wsdl/"
    xmlns:tns="http://xmlns.oracle.com/pcbpel/adapter/db/Service_Order/"
    The problem is i can not modify the namespace because the ESB WSDL (with the import) is generated by JDeveloper - any idea what is going wrong?
    Thanks and Best regards
    Thomas

  • Flat file transformation to xml with encoding in iso-8859-1

    We have a BPEL process that picks up a flat fle (fixed length), transforms it to xml and emails it. The flat file is in iso-8859-1 (when I look at special characters like e-accent's in hex).
    The basic transformation that you get from (the wizards) of BPEL don't do the trick, the special characters are corrupted and unreadable.
    After that I changed all the encoding's (in xsd's and xsl's) from utf-8 into iso-8859-1 but doesn't help either. I also added an xsl:output section to my xsl (with "encoding="iso-8859-1") but that also fails...
    Does anyone have a clue? We're using SOA Suite 10.1.3.1.
    greetings,
    Jan

    just tried that but the problem is still there
    I suspect that the output of the file adapter (reading the flat file) is already corrupted, you should be able to tell the file adapter what encoding the input file is...

  • Complex xml with multiple namespaces giving LPX-00601: Invalid token error

    Hi
    Apologies if this is a really simple question.
    I have not worked with xml before and I'm drowning in different ways to do the extract.
    I have a very complex xml, sample below, which I'm trying to do one siple extract to get myself going.
    I have the data in a table in an xmltype column,
    I am trying to extract containernumber first and get the error.
    select xml_column, extract(xml_column,'/env:Envelope/env:Body/ns0:QueryCntrNumberResponse/ns0:QueryResContainerDetail/ns1:ContainerNumber/ns2:ContainerNumber')
    from test_xml;
    Not sure if I should use the namespaces and have tried without but results are always NULL
    I would really appreciate any pointers around these ultiple namespaces.
    Thanks
    Nicki
    XML Sample
    <?xml version="1.0" encoding="UTF-8"?>
    <env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
                  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xmlns:ns0="http://com.cargosmart.cargotracking.webservice.cntr.dto"
                  xmlns:ns1="http://com.cargosmart.cargotracking.webservice.common.dto"
                  xmlns:ns2="http://com.cargosmart.cargotracking.webservice.basic.dto"
                  xmlns:ns3="http://com.cargosmart.cargotracking.webservice.bl.dto"
                  xmlns:ns4="http://com.cargosmart.cargotracking.webservice.bkg.dto">
      <env:Body>
        <ns0:QueryByCntrNumberResponse>
          <ns0:QueryRes ult="">
            <ns0:QueryCriteria>
              <ns1:CarrierSCACCode>APLU</ns1:CarrierSCACCode>
              <ns1:ContainerNumber>APZU344693-1</ns1:ContainerNumber>
            </ns0:QueryCriteria>
            <ns0:ContainerDetail>
              <ns1:ContainerNumber>
                <ns2:ContainerNumber>APZU344693</ns2:ContainerNumber>
                <ns2:ContainerCheckDigit>1</ns2:ContainerCheckDigit>
                <ns2:GrossWeight>
                  <ns2:Weight>20260.8</ns2:Weight>
                  <ns2:WeightUnit>KGS</ns2:WeightUnit>
                </ns2:GrossWeight>
              </ns1:ContainerNumber>
    NOT THE FULL COLUMN

    Could I just ask you one more question.
    I had already expanded the query to include the repeating sections using xmlsequence.
    Has that been replaced too?
                select extractvalue(xml_column,'/env:Envelope/env:Body/ns0:QueryByCntrNumberResponse/ns0:QueryResult/ns0:ContainerDetail/ns1:ContainerNumber/ns2:ContainerNumber',
                  'xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" 
                  xmlns:ns0="http://com.cargosmart.cargotracking.webservice.cntr.dto"
                  xmlns:ns1="http://com.cargosmart.cargotracking.webservice.common.dto"
                  xmlns:ns2="http://com.cargosmart.cargotracking.webservice.basic.dto"
                  xmlns:ns3="http://com.cargosmart.cargotracking.webservice.bl.dto"
                  xmlns:ns4="http://com.cargosmart.cargotracking.webservice.bkg.dto"') col1,
                  extractvalue(value(t2),'/ns1:Event/ns1:EventDescription', 'xmlns:ns1="http://com.cargosmart.cargotracking.webservice.common.dto"') Event_Description,
                  extractvalue(value(t2),'/ns1:Event/ns1:EventDT/ns2:LocDT', 'xmlns:ns1="http://com.cargosmart.cargotracking.webservice.common.dto" xmlns:ns2="http://com.cargosmart.cargotracking.webservice.basic.dto"') Event_DT,
                  extractvalue(value(t2),'/ns1:Event/ns1:Location/ns2:LocationName', 'xmlns:ns1="http://com.cargosmart.cargotracking.webservice.common.dto" xmlns:ns2="http://com.cargosmart.cargotracking.webservice.basic.dto"') location
    from test_xml t1,
    table(xmlsequence(extract(t1.xml_column,'/env:Envelope/env:Body/ns0:QueryByCntrNumberResponse/ns0:QueryResult/ns0:ContainerDetail/ns1:Event','xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" 
                  xmlns:ns0="http://com.cargosmart.cargotracking.webservice.cntr.dto"
                  xmlns:ns1="http://com.cargosmart.cargotracking.webservice.common.dto"
                  xmlns:ns2="http://com.cargosmart.cargotracking.webservice.basic.dto"
                  xmlns:ns3="http://com.cargosmart.cargotracking.webservice.bl.dto"
                  xmlns:ns4="http://com.cargosmart.cargotracking.webservice.bkg.dto"'))) t2;

  • XML with multiple namespaces

    I have an XML file
    <?xml version="1.0"?>
    -<Document xmlns="http://www.taleo.com/ws/integration/toolkit/2011/05">
    +<Attributes>
    -<Content>
    -<ExportXML xmlns="http://www.taleo.com/ws/integration/toolkit/2005/07/action/export">
    -<record>
    <field name="ContestNumber">12000000RT</field>
    <field name="JobInformation,JobType,Description">Experienced</field>
    </record>
    </ExportXML>
    </Content>
    </Document>
    I am using the following file to retrieve the data
    SELECT *
       FROM XMLTable(XMLNAMESPACES('http://www.taleo.com/ws/integration/toolkit/2011/05' as "n1",
       'http://www.taleo.com/ws/integration/toolkit/2005/07/action/export' as  "n2"), '//n1:Document/Content/n2:ExportXML/record'
                passing xmltype(
                     bfilename('TEST','TALEOOUT-12-26.xml')
                     , nls_charset_id('AL32UTF8')
         columns
         ContestName varchar2(1000) path 'field[1]'
         )What am i doing wrong

    This was the code that worked.Thanks A_Non .
    SELECT *
       FROM XMLTable(XMLNAMESPACES('http://www.taleo.com/ws/integration/toolkit/2011/05' as "n1",
       'http://www.taleo.com/ws/integration/toolkit/2005/07/action/export' as  "n2"),
       '/n1:Document/n1:Content/n2:ExportXML/n2:record'
                passing xmltype(
                     bfilename('TEST','TALEOOUT-12-26.xml')
                     , nls_charset_id('AL32UTF8')
         columns
         ContestNumber VARCHAR2 (4000) path 'n2:field[1]',
         Job_Info_JobTypDesc VARCHAR2 (4000) path 'n2:field[2]',
         JobFamily VARCHAR2 (4000) path 'n2:field[3]',.........
    )Edited by: Rameshkumar T on Nov 30, 2012 10:59 AM

  • Unable to transform XML with XSL in java code

    Hi,
    Could somebody please tell me what's wrong with my code, why it isn't transform the XML with XSL to the output that I want. If I use the command line to transform the XML, it output perfectly:
    java org.apache.xalan.xslt.Process -in marc.xml -xsl MARC21slim2MODS.xsl -out out.xml
    Here is the code of my program to transform the XML with XSL, I am using xalan-j_2_2-bin:
    import java.io.*;
    import java.net.*;
    import java.util.*;
    import org.w3c.dom.*;
    import javax.xml.parsers.*;
    import javax.xml.transform.*;
    import javax.xml.transform.stream.*;
    import javax.xml.transform.dom.*;
    import java.math.BigInteger;
    String xslDoc = "MODS.xsl";
    String xmlResult = "out.xml";
    DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
    dfactory.setNamespaceAware(true);
    DocumentBuilder docBuilder = dfactory.newDocumentBuilder();
    Document xmlDoc = docBuilder.newDocument();
    Element root = xmlDoc.createElement("collection");
    root.setAttribute("xmlns", "http://www.loc.gov/MARC21/slim");
    xmlDoc.appendChild(root);
    TransformerFactory factory = TransformerFactory.newInstance();
    Transformer transformer = factory.newTransformer(new StreamSource(xslDoc));
    FileWriter fw = new FileWriter(new File(xmlResult));
    StreamResult output = new StreamResult(fw);
    transformer.transform(new DOMSource(xmlDoc), output);
    fw.flush();
    fw.close();
    ========================
    marc.xml -- source XML file
    ========================
    <?xml version="1.0" encoding="UTF-8"?>
    <collection xmlns="http://www.loc.gov/MARC21/slim"><record><leader>01488cam 2200337 a 4500</leader><controlfield tag="001">2502929</controlfield><controlfield tag="005">19930521155141.9</controlfield><controlfield tag="008">920219s1993 caua j 000 0 eng </controlfield><datafield ind1=" " ind2=" " tag="035"><subfield code="9">(DLC) 92005291</subfield></datafield><datafield ind1=" " ind2=" " tag="906"><subfield code="a">7</subfield><subfield code="b">cbc</subfield><subfield code="c">orignew</subfield><subfield code="d">1</subfield><subfield code="e">ocip</subfield><subfield code="f">19</subfield><subfield code="g">y-gencatlg</subfield></datafield>
    </record></collection>
    ========================
    out.xml -- result using command line
    ========================
    <?xml version="1.0" encoding="UTF-8"?>
    <collection xmlns="http://www.loc.gov/mods/" xmlns:xlink="http://www.w3.org/TR/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.loc.gov/mods/ http://www.loc.gov/standards/marcxml/schema/mods.xsd">
    <mods>
    <titleInfo>
    <title>Arithmetic</title>
    </titleInfo>
    <name type="personal">
    <namePart>Sandburg, Carl</namePart>
    <namePart type="date">1878-1967</namePart>
    <role>creator</role>
    </name>
    </mods>
    </collection>
    ========================
    out.xml -- result using my java program
    ========================
    <?xml version="1.0" encoding="UTF-8"?>
    <collection xmlns="http://www.loc.gov/mods/" xmlns:xlink="http://www.w3.org/TR/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.loc.gov/mods/ http://www.loc.gov/standards/marcxml/schema/mods.xsd">01488cam 2200337 a 4500250292919930521155141.9920219s1993 caua j 000 0 eng (DLC) 920052917cbcorignew1ocip19y-gencatlgpc16 to br00 02-19-92; br02 to SCD 02-21-92; fd11 02-24-92 (PS3537.A618 A...); fa00 02-26-92; fa05 03-02-92; fm31 03-06-92; CIP ver. pv08 04-16-93; pv01 to CLT 04-20-93; lb10 05-21-93
    </collection>

    I am using the same XSL file. My Java program use the same XSL file I used in the command line.
    It is possible that my Java code is using a different parser, but I developed a seperate program to parse the XML using the same parser that my Java code is using. It output the result I expected. Here is the code for the program:
    import java.io.*;
    import javax.xml.transform.*;
    import javax.xml.transform.stream.*;
    public class Convertor {
    public static void main(String[] args) throws Exception {
    String xslDoc = "MARC21slim2MODS.xsl";
    String xmlResult = "out.xml";
    String xmlDoc = marc.xml";
    TransformerFactory factory = TransformerFactory.newInstance();
    Transformer transformer = factory.newTransformer(new StreamSource(xslDoc));
    StreamSource xmlSource = new StreamSource(xmlDoc);
    FileWriter fw = new FileWriter(new File(xmlResult));
    StreamResult output = new StreamResult(fw);
    transformer.transform(xmlSource, output);
    }

  • Output XML with a default namespace using XQuery

    I'm having a problem with namespaces in an XQuery within ALSB.
    We receive XML from a file which doesn't have any namespace and have to transform it into a different structure, giving it a default namespace such as below:
    Input XML
    <inputRoot>
         <inputAccountName>Joe Bloggs</inputAccountName>
         <inputAccountNumber>10938393</inputAccountNumber>
    </inputRoot>
    Desired output XML
    <outputRoot xmlns="http://www.example.org/outputSchema">
         <outputAccounts>
              <outputAccountName>Joe Bloggs</outputAccountName>
              <outputAccountNumber>10938393</outputAccountNumber>
         </outputAccounts>
    </outputRoot>
    When I attempt to do this using XQuery mapper tool, I end up with a namespace prefix on the outputRoot. The XQuery and result follows:
    XQuery
    declare namespace xf = "http://tempuri.org/XQueryProject/scratchTransformations/test/";
    declare namespace ns0 = "http://www.example.org/outputSchema";
    declare function xf:test($inputRoot1 as element(inputRoot))
    as element(ns0:outputRoot) {
    <ns0:outputRoot>
    <outputAccounts>
    <outputAccountName>{ data($inputRoot1/inputAccountName) }</outputAccountName>
    <outputAccountNumber>{ data($inputRoot1/inputAccountNumber) }</outputAccountNumber>
    </outputAccounts>
    </ns0:outputRoot>
    declare variable $inputRoot1 as element(inputRoot) external;
    xf:test($inputRoot1)
    Result
    <ns0:outputRoot xmlns:ns0="http://www.example.org/outputSchema">
         <outputAccounts>
              <outputAccountName>inputAccountName_1</outputAccountName>
              <outputAccountNumber>inputAccountNumber_1</outputAccountNumber>
         </outputAccounts>
    </ns0:outputRoot>
    How can I write the XQuery in such a way thay the namespace prefix isn't output? I've tried many different methods with no success. I can't declare a default element namespace because my input element doesn't have a namespace
    Thanks in advance

    I spoke too soon, it didn't work quite as perfectly as I'd thought :-) It turns out our client can't handle the xml with the namespace prefix but we've worked out the solution to return XML in the format we originally needed.
    Example below:
    XQuery
    declare namespace xf = "http://tempuri.org/XQueryProject/scratchTransformations/test/";
    declare default element namespace "http://www.example.org/outputSchema";
    declare namespace ns1 = ""
    declare function xf:test($inputRoot1 as element(ns1:inputRoot))
    as element(outputRoot) {
    <outputRoot>
    <outputAccounts>
    <outputAccountName>{ data($inputRoot1/inputAccountName) }</outputAccountName>
    <outputAccountNumber>{ data($inputRoot1/inputAccountNumber) }</outputAccountNumber>
    </outputAccounts>
    </outputRoot>
    declare variable $inputRoot1 as element(inputRoot) external;
    xf:test($inputRoot1)

  • Error with XSL Transformation

    From my application log I see an exception where it tries to call the oracle.xml.parser.v2.XSLProcessor.
    The servlet for the login screen (XSL transformation) takes XML and returns HTML. Actually for the xml parsing
    we use xerces I don't understand why we would call the ORACLE parser? Do you have any idea? Is this a CLASSPATH
    or configuration problem? Is there a way to use the xml parser xerces instead the oracle one.
    <log4j:event logger="com.siemens.srvcmgmt.common.server.PresentationHandler" timestamp="1052834094464" level="DEBUG" thread="ApplicationServerThread-5">
    <log4j:message><![CDATA[Error: ]]></log4j:message>
    <log4j:NDC><![CDATA[1 Security doPost sendLoginScreen PresentationHandler transformIt]]></log4j:NDC>
    <log4j:throwable><![CDATA[java.lang.NullPointerException
    at java.util.Hashtable.put(Hashtable.java:375)
    at oracle.xml.parser.v2.XSLProcessor.setParam(XSLProcessor.java:658)
    at oracle.xml.jaxp.JXTransformer.setParameter(JXTransformer.java:385)
    at com.siemens.srvcmgmt.common.server.PresentationHandler.transformIt(PresentationHandler.java:149)
    at com.siemens.srvcmgmt.smc.servlet.Security.sendLoginScreen(Security.java:596)
    at com.siemens.srvcmgmt.smc.servlet.Security.doPost(Security.java:105)
    at com.siemens.srvcmgmt.smc.servlet.Security.doGet(Security.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
    at com.evermind.server.http.ResourceFilterChain.doFilter(ResourceFilterChain.java:65)
    at oracle.security.jazn.oc4j.JAZNFilter.doFilter(JAZNFilter.java:283)
    at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:560)
    at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:306)
    at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:767)
    at com.evermind.server.http.AJPRequestHandler.run(AJPRequestHandler.java:148)
    at com.evermind.server.http.AJPRequestHandler.run(AJPRequestHandler.java:72)
    at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(PooledExecutor.java:797)
    at java.lang.Thread.run(Thread.java:479)
    ]]></log4j:throwable>

    From my application log I see an exception where it tries to call the oracle.xml.parser.v2.XSLProcessor.
    The servlet for the login screen (XSL transformation) takes XML and returns HTML. Actually for the xml parsing
    we use xerces I don't understand why we would call the ORACLE parser? Do you have any idea? Is this a CLASSPATH
    or configuration problem? Is there a way to use the xml parser xerces instead the oracle one.
    <log4j:event logger="com.siemens.srvcmgmt.common.server.PresentationHandler" timestamp="1052834094464" level="DEBUG" thread="ApplicationServerThread-5">
    <log4j:message><![CDATA[Error: ]]></log4j:message>
    <log4j:NDC><![CDATA[1 Security doPost sendLoginScreen PresentationHandler transformIt]]></log4j:NDC>
    <log4j:throwable><![CDATA[java.lang.NullPointerException
    at java.util.Hashtable.put(Hashtable.java:375)
    at oracle.xml.parser.v2.XSLProcessor.setParam(XSLProcessor.java:658)
    at oracle.xml.jaxp.JXTransformer.setParameter(JXTransformer.java:385)
    at com.siemens.srvcmgmt.common.server.PresentationHandler.transformIt(PresentationHandler.java:149)
    at com.siemens.srvcmgmt.smc.servlet.Security.sendLoginScreen(Security.java:596)
    at com.siemens.srvcmgmt.smc.servlet.Security.doPost(Security.java:105)
    at com.siemens.srvcmgmt.smc.servlet.Security.doGet(Security.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
    at com.evermind.server.http.ResourceFilterChain.doFilter(ResourceFilterChain.java:65)
    at oracle.security.jazn.oc4j.JAZNFilter.doFilter(JAZNFilter.java:283)
    at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:560)
    at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:306)
    at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:767)
    at com.evermind.server.http.AJPRequestHandler.run(AJPRequestHandler.java:148)
    at com.evermind.server.http.AJPRequestHandler.run(AJPRequestHandler.java:72)
    at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(PooledExecutor.java:797)
    at java.lang.Thread.run(Thread.java:479)
    ]]></log4j:throwable>

  • XSL transformation never works on Websphere 5

    I'm doing a xsl transformation on websphere 5 and this xsl never finds the right values. When I run the exact same transformation with the same source, it finds all the values, but on the server it just return empty tags. Why? And how do I fix this?
    Source xml:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <n:OrderResponseComplex xmlns:n="http://sirius/xml/common">
         <n:AcceptedIndicator>Akseptert</n:AcceptedIndicator>
         <n:RejectionReasonCode>0</n:RejectionReasonCode>
    </n:OrderResponseComplex>XSL transformation:
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:xalan="http://xml.apache.org/xslt">
         <xsl:template match="/">
              <SiebelMessage IntObjectFormat="Siebel Hierarchical" IntObjectName="TBS2 OHS Reply" MessageType="Integration Object">
                   <TBS2OHSReply>
                        <OrderEntry-Orders>
                             <BackOfficeErrorText><xsl:value-of select="OrderResponseComplex/RejectionReasonCode"/></BackOfficeErrorText>
                             <Status><xsl:value-of select="OrderResponseComplex/AcceptedIndicator"/></Status>
                        </OrderEntry-Orders>
                   </TBS2OHSReply>
              </SiebelMessage>
         </xsl:template>
    </xsl:stylesheet>Result xml:
    <?xml version="1.0" encoding="UTF-8"?>
    <SiebelMessage MessageType="Integration Object" IntObjectName="TBS2 OHS Reply" IntObjectFormat="Siebel Hierarchical">
         <TBS2OHSReply>
              <OrderEntry-Orders>
                   <BackOfficeErrorText/>
                   <Status/>
              </OrderEntry-Orders>
         </TBS2OHSReply>
    </SiebelMessage>

    You need to watch out for the namespace in the source document:
    You can either specify the namespace and use it when locating paths in the source document (as below) or specify it as the default namespace.
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet
         xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
         version="1.0"
         xmlns:xalan="http://xml.apache.org/xslt"
         xmlns:n="http://sirius/xml/common">
    <xsl:template match="/">          
         <SiebelMessage IntObjectFormat="Siebel Hierarchical" IntObjectName="TBS2 OHS Reply" MessageType="Integration Object">
              <TBS2OHSReply>                    
                   <OrderEntry-Orders>                         
                        <BackOfficeErrorText><xsl:value-of select="n:OrderResponseComplex/n:RejectionReasonCode"/></BackOfficeErrorText>
                        <Status><xsl:value-of select="n:OrderResponseComplex/n:AcceptedIndicator"/></Status>
                   </OrderEntry-Orders>
              </TBS2OHSReply>
         </SiebelMessage>
    </xsl:template>
    </xsl:stylesheet>

  • XSL transformation not working

    Hi!
    I am having problems when trying to generate XSL transformation from XML to XML (where XML output is actually XHTML). It always fails executing <xsl:callTemplate name="something", when <xsl:callTemplate /> is executed from another <xsl:template> which is also called with <xsl:callTemplate. Version of database is 10.2.0.4.0, received error is: ORA-00604: invalid character value 'burek' for attribute 'name'.
    Transformation is working in Java and Altova XMLSpy.
    PL/SQL code:
    procedure process_xsl(p_xml in clob, p_xsl in clob, p_result out clob) is
    w_xsl_proc dbms_XSLProcessor.Processor;
    w_xsl_ss dbms_XSLProcessor.Stylesheet;
    w_dom_xsl dbms_xmldom.DOMDocument;
    w_dom_xml dbms_xmldom.DOMDocument;
    w_parser dbms_xmlparser.Parser;
    begin
    --xml in xsl iz cloba v DOMDocument
    w_parser := dbms_xmlparser.newParser;
    dbms_xmlparser.parseClob(w_parser, p_xml);
    w_dom_xml := dbms_xmlparser.getDocument(w_parser);
    dbms_xmlparser.freeParser(w_parser);
    w_parser := dbms_xmlparser.newParser;
    dbms_xmlparser.parseClob(w_parser, p_xsl);
    w_dom_xsl := dbms_xmlparser.getDocument(w_parser);
    dbms_xmlparser.freeParser(w_parser);
    --xsl procesiranje
    w_xsl_proc := dbms_XSLProcessor.newProcessor;
    w_xsl_ss := dbms_XSLProcessor.newStylesheet(w_dom_xsl, null); <-- Here error is received
    END;
    Stylesheet:
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
         <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"></xsl:output>
         <xsl:decimal-format name="dec" decimal-separator="," grouping-separator="."/>
         <!-- Predefined constants from einvoice xml schema -->
         <xsl:variable name="einvoiceIssuerCode" select="'II'"></xsl:variable>
         <xsl:variable name="einvoiceRecipientCode" select="'IV'"></xsl:variable>
         <xsl:variable name="einvoiceIssueLocationCode" select="91"></xsl:variable>
         <xsl:variable name="einvoiceIssueDateCode" select="137"></xsl:variable>
         <!-- Constants directly from document which is a part of transformation -->
         <xsl:variable name="einvoiceNumber" select="/IzdaniRacunEnostavni/Racun/GlavaRacuna/StevilkaRacuna/text()"></xsl:variable>
         <!-- Intro template -->
         *<xsl:template name="burek"> <!-- Second template called with xsl:call template -->*
              <xsl:text>TEST</xsl:text>
         </xsl:template>
         <!-- Template in which we create html structure including css -->
         <xsl:template name="einvoice">
              <html xmlns="http://www.w3.org/1999/xhtml">
              <head>
                   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
                   <title>Vizualizacija e-računa št. </title>
                   <xsl:call-template name="burek"></xsl:call-template>
              </head>
              <body>
              </body>
              </html>
         </xsl:template>
         <!-- Intro template -->
         <xsl:template match="/">
    *          <xsl:call-template name="einvoice"></xsl:call-template> <!-- This call is OK -->*
         </xsl:template>
    </xsl:stylesheet>
    XML document
    <?xml version="1.0" encoding="UTF-8"?>
    <IzdaniRacunEnostavni>
    <Racun Id="data">
    <GlavaRacuna>
    <VrstaRacuna>380</VrstaRacuna>
    <StevilkaRacuna>1205019908211</StevilkaRacuna>
    <FunkcijaRacuna>9</FunkcijaRacuna>
    </GlavaRacuna>
    <DatumiRacuna>
    <VrstaDatuma>137</VrstaDatuma>
    <DatumRacuna>2012-05-07T00:00:00.0Z</DatumRacuna>
    </DatumiRacuna>
    <DatumiRacuna>
    <VrstaDatuma>263</VrstaDatuma>
    <DatumRacuna>2012-04-28T00:00:00.0Z</DatumRacuna>
    </DatumiRacuna>
    <DatumiRacuna>
    <VrstaDatuma>263</VrstaDatuma>
    <DatumRacuna>2012-05-27T00:00:00.0Z</DatumRacuna>
    </DatumiRacuna>
    <DatumiRacuna>
    <VrstaDatuma>263</VrstaDatuma>
    <DatumRacuna>2012-03-28T00:00:00.0Z</DatumRacuna>
    </DatumiRacuna>
    <DatumiRacuna>
    <VrstaDatuma>263</VrstaDatuma>
    <DatumRacuna>2012-04-26T00:00:00.0Z</DatumRacuna>
    </DatumiRacuna>
    <DatumiRacuna>
    <VrstaDatuma>263</VrstaDatuma>
    <DatumRacuna>2012-04-27T00:00:00.0Z</DatumRacuna>
    </DatumiRacuna>
    <Lokacije>
    <VrstaLokacije>91</VrstaLokacije>
    <NazivLokacije>Ljubljana</NazivLokacije>
    </Lokacije>
    </Racun>
    </IzdaniRacunEnostavni>
    Edited by: 938026 on 01-Jun-2012 00:35

    Hi,
    I think your problem lies in the <title>. You are using non UTF-8 characters in the title (š), but you marked your XML as UTF-8. So change the title to have unicode charaters and it will work.
    Herald ten Dam
    http://htendam.wordpress.com

  • XPath expression with multiple namespaces?

    Hello all.
    I have been scouring the forums and Google and can't seem to find anything similar to my problem.
    I have the following XML with three namespaces. Two are defined in the root element and the third is defined in the the IdSession element. To make things even more confusing, the second and third namespaces have the same prefix, 'f'.
    This is the xml:
    <?xml version="1.0" encoding="ISO-8859-1" ?>
    <NamespaceTestCall xmlns="http://my.default/namespace"
    xmlns:f="http://my.second/namespace">
    ...<f:Level1>
    ......<f:IdSession xmlns:f="http://my.third/namespace">12345</f:IdSession>
    ......<Language>ENG</Language>
    ...</f:Nivel1>
    </NamespaceTestCall>
    My question is, how do I get at the IdSession element? Don't I need to create an XPath object and assign it more than one NamespaceContext?
    This is what I am doing:
    Document xmlDocument = loadXML(xmlSource);
    XPath xpathEvaluator = XPathFactory.newInstance().newXPath();
    xpathEvaluator.setNamespaceContext(new NamespaceContextProvider("a", "http://my.third/namespace"));
    ... xpathEvaluator.evaluate("//a:IdSession", ...);
    This code works but it might not return the 'IdSession' I want, since by searching like this '//a:IdSession' it is looking in the whole document. If there were another 'IdSession' somewhere else in the document with the same URI, it would be returned. I want the 'IdSession' that lives inside of 'Level1'.
    So what I would like to do is something like this:
    ... xpathEvaluator.evaluate("/*/Level1/a:IdSession", ...);
    But this does NOT work because 'Level1' has its own namespace. So what it seems like I need to do is the following:
    ... xpathEvaluator.evaluate("/*/b:Level1/a:IdSession", ...);
    Having already added the 'Level1' namespace to the XPath object, with the prefix 'b'. But unlike JDOM, there is no 'add' functionality, only 'set', meaning if you call set twice the second call overwrites the first.
    Is there anyway to do this?
    Many thanks!
    Bob

    Hello,
    Sorry, that was my bad. I should have explained that NamespaceContextProvider is nothing more than my implementation of the NamespaceContext interface. The way I did it, I simply implemented getNamespaceURI() and getPrefix(). And the constructor accepted two parameters -- prefix and URI. So my problem was that when I assigned this NamespaceContext to my XPath object it would only have one prefix and one URI.
    But I found an implementation here:
    http://www.oreillynet.com/cs/user/view/cs_msg/50304
    that instead of only having one prefix and URI uses a map. Thus its method setNamespace() adds the prefix and URi to the map, and getPrefix() and getPrefixes() retrieve them from the map.
    Now when I want to use more than one namespace I simply call setNamespace() as many times as necessary, adding a prefix and URI pair each time, and when I am done I assign it to my XPath object.
    And it works!
    Thanks for the response!
    Bob

  • How can I use JavaScript extention functions with Xalan for transforming XML with XSL

    While transforming standart XML and XSL files to HTML with this servlet:
    package mypackage1;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    import java.util.*;
    import java.net.URL;
    import javax.xml.transform.*;
    import javax.xml.transform.stream.StreamSource;
    import javax.xml.transform.stream.StreamResult;
    import org.mozilla.javascript;
    public class Servlet2 extends HttpServlet
    private static final String CONTENT_TYPE = "text/html; charset=windows-1252";
    public void init(ServletConfig config) throws ServletException
    super.init(config);
    public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException
    try
    response.setContentType(CONTENT_TYPE);
    PrintWriter out = response.getWriter();
    TransformerFactory tFactory = TransformerFactory.newInstance();
    Source xmlSource = new StreamSource(new FileReader("c:/aaa.xml"));
    Source xslSource = new StreamSource(new FileReader("c:/bbb.xsl"));
    Transformer transformer = tFactory.newTransformer(xslSource);
    transformer.transform (xmlSource, new StreamResult(out));
    catch (Exception e)
    e.printStackTrace();
    everything is going ok,
    but when try to use javascript function in XSL file, for example like in this:
    <?xml version="1.0"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
    xmlns:lxslt="http://xml.apache.org/xslt" xmlns:my-ext="ext1"
    extension-element-prefixes="my-ext">
    <lxslt:component prefix="my-ext"
    functions="getdate">
    <lxslt:script lang="javascript">
    function getdate() {
    var d = new Date();
    return d.toUTCString();
    </lxslt:script>
    </lxslt:component>
    <xsl:template match="/">
    <p><xsl:copy-of select="my-ext:getdate()"/></p>
    </xsl:template>
    </xsl:stylesheet>
    recieve error-message:
    XSL-1000: (Fatal Error) Error while parsing XSL file (Extension function namespace should start with 'http://www.oracle.com/XSL/Transform/java/'.).
    What kind of namespace I should specify?

    Hello, Paul.
    I'm sure you may not use JavaScript as a language for creating XSLT extention functions with Oracle XDK Parser. This is since parser might have JavaScript interpreter to work with JavaScript, but it has not.
    If you need to build any XSLT extention functions you must build them as Java class' static methods.
    After that, you define the usage of the class by mean of namespace declaration as:
    xmlns:your-ns="http://www.oracle.com/XSL/Transform/java/yourpackage.Yourclass"
    (Prefix "http://www.oracle.com/XSL/Transform/java/" may differs if you use non-Oracle XML parser)
    and use class' static method in XSLT:
    <xsl:value-of select="your-ns.staticMethodName(paramsIfAny)"/>
    In your case you may wish to use standard Date class:
    xmlns:date="http://www.oracle.com/XSL/Transform/java/java.util.Date"
    <xsl:value-of select="date:toString(date:new)"/>

  • Error: "... is not a table ..." XML not correctly interpreted after XSL-transformation. Table row quantity problem.

    Hey guys, this is one of my xml-elements:
    Jaspreet Sohi 12 18 Juliane Lenz 11 17 Sophie Charlotte Stender 10 15 Rosbeh Hamidzadeh Khayyat 12 17 Lion Stoldt 12 17 Mats Lucas Meincke 6 8 Bero Luke Vincent Ernst 6 8 Cedric Roth 6 8 Soner Cantay 6 8 The following XSL Transformation I use once for transforming all "m" tags and once in order to transform all "j" tags. Please imagine the CSL-code below to be duplicated exactly. Only the "jungs"-table-Tag is replaced by "mädchen" and all underscores _j are replace by _m. As well all "select="j[@..." parts are replaced by "select="m[@...". 1 2 3 The code is very easygoing I think and not difficult to understand. As I said, I use it twice - for both transformations. The very, extremely weird thing, my problem, is that one transformation works perfectly in InDesign and a table is created for all "kategorie"-tags (all is set within a for-each loop). But the second script does not work! I simply do not get this I can't understand it. I've tried more than anything. InDesign sais (in German, so translated based on assumption) "jungs is an invalid table element or is displayed in wrong order". The second strange thing is that I can replace my "aid:trows" attribute by any number, e.g. "10" and immediately the script works fine (as there are never more than 6 "j" tags in my XML so that never the table has more than 6 rows"). But it does not want to work correctly with the actual number, my variable "rows_j". These are my variables: They are all defined before the tables for m and j are created. So finally, why (the heck) is one table created and interpreted perfectly whereas the second - immediately following the first in the XSL.script as an EXACT copy of the first - results in an error? As i've already said, I've tried really everything. For example the script works also when one of the parts "" is randomly deleted from the script. Removing one of these parts directly makes the script working. Just one of my attempts to understand the thing but this has only shown that none of these parts "cell to end-for-each" includes an error. I'm really desperate and looking forward to being rescued by one of you geniuses :)

    Hah, No worries. The forum software is, well, different.
    What would be better, though, would be a sample ID file, any XSLT/XLT files you use, and a bit of data exactly as you have it (pre-transform state). ZIP it up, upload to say dropbox.com and feel free to send me a private message for the download link.
    Too many times there is something different between samples pasted into a post and the real thing that it is sometimes less useful time-wise. I'll keep it private, of course. Then we can communicate via PMs or email until we can (hopefully) arrive together at a solution, then post what that solution is in the forum to benefit others.
    Thank you, Mike

Maybe you are looking for