Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

XSL: Transformation adds spurious attributes?

Posted on 2005-04-13
8
Medium Priority
?
339 Views
Last Modified: 2013-11-19
Hi,

We are using Java to perform an XSL Transformation on an XML document. All is well apart from two elements which are passed in with no attributes but come out with:

xml:lang="en-GB"

attribute added? The XSL is very simple and takes the input adds some new elements and returns the amended XML:

<?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" indent="yes" />
 
  <xsl:template match="/ | @* | node()">
    <xsl:copy>
      <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>
  </xsl:template>
 
     <xsl:template match="TemporaryItemDs[last()]">
    <xsl:copy>
      <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>
         <xsl:for-each select="../FieldSupportInformation/JobPack/*">
              <TemporaryItemDs>
                 <TemporaryItemCode>JBPCK<xsl:value-of select="position()"/></TemporaryItemCode>
                  <TemporaryItemValue>"<xsl:value-of select="." />"</TemporaryItemValue>
              </TemporaryItemDs>
         </xsl:for-each>      
     </xsl:template>
</xsl:stylesheet>

Can anybody tell me why this attribute is being added and how I can stop it from being added? The only option I can currently think of is to do a string replace on it but that is a bit of a hack, so I hope there is a flag to switch off which will prevent it from being added in the first place?

Thanks
Scott
0
Comment
Question by:scurtis_1
  • 5
  • 3
8 Comments
 
LVL 35

Expert Comment

by:TimYates
ID: 13770944
Can you post a sample XML and the output with the extra tags?
0
 
LVL 35

Expert Comment

by:TimYates
ID: 13770949
And the code you are using to blend the two...
0
 

Author Comment

by:scurtis_1
ID: 13771028
TimYates,

Input XML:

<!DOCTYPE TaskInitiateDs SYSTEM "createTask.dtd">
<TaskInitiateDs>
  <SourceSystem>UIEE</SourceSystem>
  <TaskIdentifier>HTHT00026</TaskIdentifier>
  <TaskTypeDs>
    <TaskCategory>N</TaskCategory>
    <TaskTypeId>SUF</TaskTypeId>
    <SkillDurationDs>
      <SkillCode>AAA</SkillCode>
      <Duration>25</Duration>
    </SkillDurationDs>
  </TaskTypeDs>
  <BusinessAssetIdCode>PJ5</BusinessAssetIdCode>
  <MainWorkLocation>CA</MainWorkLocation>
  <ResponseCode>NONE</ResponseCode>
  <PostCode>HTG 123</PostCode>
  <WorkAddressDs>
    <WorkLocationQualifier>C</WorkLocationQualifier>
    <AddressLine>89 ROAD</AddressLine>
    <AddressLine>HEMEL HEMPSTEAD</AddressLine>
    <ContactName>John Doe</ContactName>
    <ContactPhoneNo>2132132131</ContactPhoneNo>
    <AddressPostcode>HTG 123</AddressPostcode>
  </WorkAddressDs>
  <ImportanceClass>12</ImportanceClass>
  <CAPCInd>Y</CAPCInd>
  <CustomerName>John Doe</CustomerName>
  <RepeatReportIndicator/>
  <TemporaryItemDs>
    <TemporaryItemCode>PROD</TemporaryItemCode>
    <TemporaryItemValue>Product Code</TemporaryItemValue>
  </TemporaryItemDs>
  <TaskDescription/>
  <TaskNotesDs>
    <NoteType>NTE</NoteType>
    <NoteText>Notes</NoteText>
  </TaskNotesDs>
  <PrimaryCommitmentDs>
    <AppointmentDs>
      <AppointmentWindowDs>
        <EarliestStartDateTime>200401010000</EarliestStartDateTime>
        <LatestStartDateTime>200412312359</LatestStartDateTime>
      </AppointmentWindowDs>
    </AppointmentDs>
  </PrimaryCommitmentDs>
  <FieldSupportInformation>
    <JobPack>
      <JobPackURL>TestJobPackURL1</JobPackURL>
    </JobPack>
    <ClosureControl>
      <RetroStoresRequired>True</RetroStoresRequired>
      <StoresReturnedRequired>True</StoresReturnedRequired>
      <ReinstatementInfoRequired>True</ReinstatementInfoRequired>
      <POIInformationRequired>True</POIInformationRequired>
      <SurveyInformationRequired>True</SurveyInformationRequired>
      <CalibratedEquipmentRequired>True</CalibratedEquipmentRequired>
      <WayleaveRequired>True</WayleaveRequired>
      <GridReferenceRequired>True</GridReferenceRequired>
      <TestResultsRequired>True</TestResultsRequired>
    </ClosureControl>
    <AdditionalClosureDetail>
      <Audit>
        <Question>jhdgj&amp;kuh&gt; &lt;  &lt; of Q &gt; uestion 1</Question>
      </Audit>
    </AdditionalClosureDetail>
  </FieldSupportInformation>
</TaskInitiateDs>

Output XML:

<!DOCTYPE TaskInitiateDs SYSTEM "createTask.dtd">
<TaskInitiateDs xml:lang="en-GB">
  <SourceSystem>UIEE</SourceSystem>
  <TaskIdentifier>HTHT00026</TaskIdentifier>
  <TaskTypeDs>
    <TaskCategory>N</TaskCategory>
    <TaskTypeId>SUF</TaskTypeId>
    <SkillDurationDs>
      <SkillCode>AAA</SkillCode>
      <Duration>25</Duration>
    </SkillDurationDs>
  </TaskTypeDs>
  <BusinessAssetIdCode>PJ5</BusinessAssetIdCode>
  <MainWorkLocation>CA</MainWorkLocation>
  <ResponseCode>NONE</ResponseCode>
  <PostCode>HTG 123</PostCode>
  <WorkAddressDs>
    <WorkLocationQualifier>C</WorkLocationQualifier>
    <AddressLine>89 ROAD</AddressLine>
    <AddressLine>HEMEL HEMPSTEAD</AddressLine>
    <ContactName>John Doe</ContactName>
    <ContactPhoneNo>2132132131</ContactPhoneNo>
    <AddressPostcode>HTG 123</AddressPostcode>
  </WorkAddressDs>
  <ImportanceClass>12</ImportanceClass>
  <CAPCInd>Y</CAPCInd>
  <CustomerName>John Doe</CustomerName>
  <RepeatReportIndicator/>
  <TemporaryItemDs>
    <TemporaryItemCode>PROD</TemporaryItemCode>
    <TemporaryItemValue>Product Code</TemporaryItemValue>
  </TemporaryItemDs>
  <TemporaryItemDs>
    <TemporaryItemCode>JBPCK1</TemporaryItemCode>
    <TemporaryItemValue>"TestJobPackURL1"</TemporaryItemValue>
  </TemporaryItemDs>
  <TaskDescription/>
  <TaskNotesDs>
    <NoteType>NTE</NoteType>
    <NoteText>Notes</NoteText>
  </TaskNotesDs>
  <PrimaryCommitmentDs>
    <AppointmentDs>
      <AppointmentWindowDs>
        <EarliestStartDateTime>200401010000</EarliestStartDateTime>
        <LatestStartDateTime>200412312359</LatestStartDateTime>
      </AppointmentWindowDs>
    </AppointmentDs>
  </PrimaryCommitmentDs>
  <FieldSupportInformation xml:lang="en-GB">
    <JobPack>
      <JobPackURL>TestJobPackURL1</JobPackURL>
    </JobPack>
    <ClosureControl>
      <RetroStoresRequired>True</RetroStoresRequired>
      <StoresReturnedRequired>True</StoresReturnedRequired>
      <ReinstatementInfoRequired>True</ReinstatementInfoRequired>
      <POIInformationRequired>True</POIInformationRequired>
      <SurveyInformationRequired>True</SurveyInformationRequired>
      <CalibratedEquipmentRequired>True</CalibratedEquipmentRequired>
      <WayleaveRequired>True</WayleaveRequired>
      <GridReferenceRequired>True</GridReferenceRequired>
      <TestResultsRequired>True</TestResultsRequired>
    </ClosureControl>
    <AdditionalClosureDetail>
      <Audit>
        <Question>jhdgj&amp;kuh&gt; &lt;  &lt; of Q &gt; uestion 1</Question>
      </Audit>
    </AdditionalClosureDetail>
  </FieldSupportInformation>
</TaskInitiateDs>

Notice the TaskInitiateDs and FieldSupportInformation fields now have the attribute added?

The code used to perform the transformation is:

private static Source xsltSource = null;
public static void loadXSL(String xslFilename) {

    File xsltFile = new File(xslFilename);
    xsltSource = new javax.xml.transform.stream.StreamSource(xsltFile);
}

public String translateXML(String payload) throws TransformerException {

    StringWriter returnString = new StringWriter();
    StringReader strReader = new StringReader(payload);

    javax.xml.transform.Source xmlSource = new javax.xml.transform.stream.StreamSource(strReader);
    javax.xml.transform.Result result = new javax.xml.transform.stream.StreamResult(returnString);

    javax.xml.transform.TransformerFactory transFact = javax.xml.transform.TransformerFactory.newInstance(  );
    javax.xml.transform.Transformer trans = null;
    trans = transFact.newTransformer(xsltSource);

    // Create a new XML string using the old XML file and the xsl file
    trans.transform(xmlSource, result);

    return returnString.toString();
}
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 35

Expert Comment

by:TimYates
ID: 13771089
have you got the DTD as well?  It won't run without it :-(

(just trying it out now)
0
 
LVL 35

Accepted Solution

by:
TimYates earned 500 total points
ID: 13771097
Actually, if I remove

     SYSTEM "createTask.dtd"

from the xml... It doesn't recreate the problem...
0
 

Author Comment

by:scurtis_1
ID: 13771106
Tim,

There are several DTDs. If you sent me your email address I will send them as attachments by reply?

My email address is: scurtis at gmail dot com

Thanks
Scott
0
 

Author Comment

by:scurtis_1
ID: 13771153
Tim,

Actually, I have just worked out what is wrong. I bothered to look into the DTDs and noticed:

<!ATTLIST TaskInitiateDs
      xml:lang CDATA #FIXED "en-GB"
>

My understanding of DTDs is limited but I guess this tells the XSL transformation engine to add this fixed attribute if it isn't specified? Therefore it is all working ok after all!

Thanks for trying it out. For your efforts and pointing my back to the DTDs I will give you the points. And you were on the mark with your previous comment about removing the DTDs from the input xml anyway!

Thanks
Scott
0
 
LVL 35

Expert Comment

by:TimYates
ID: 13771215
:-)  cool  :-)

Good luck with it all!

And thanks for the points :-)

Tim
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP.  This article does that, replacing as much as possible the pr…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
This video teaches viewers about errors in exception handling.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
Suggested Courses
Course of the Month15 days, 19 hours left to enroll

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question