开发者

After transformation getting output in text instead of xml nodes

My problem is after executing xlst file i am getting the output in text all in one line, but not in xml as required. My xml as well as xslt file is as follows.

<root>
  <Jobs Found="10" Returned="50"> 
  <Job ID="8000000" PositionID="600002"> 
  开发者_Go百科<Title>Development Manager</Title>  
  <Summary> 
     <![CDATA[ An experienced Development Manager with previous experience leading a small to mid-size team of developers in a Java/J2EE environment. A hands on role, you will be expected to manage and mentor a team of developers working on a mix of greenfield and maintenance projects.&#160;&#160; My client, a well known investment bank, requires an experienced Development Manager to join their core technology team. This t 
  ]]>  
  </Summary> 
  <DateActive Date="2009-10-06T19:36:43-05:00">10/6/2009</DateActive>  
  <DateExpires Date="2009-11-05T20:11:34-05:00">11/5/2009</DateExpires>  
  <DateUpdated Date="2009-10-06 20:12:00">10/6/2009</DateUpdated>  
  <Location> 
    <Country>xxxx</Country>  
    <State>xxx</State>  
    <City>xxx</City>  
    <PostalCode>xxx</PostalCode>  
  </Location> 
  <CompanyName>abc Technology</CompanyName>  
  <BuilderFields />  
  <DisplayOptions />  
  <AddressType>1234</AddressType>  
  </Job> 
      </Jobs>
</root>

XSLT stylesheet:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
  <xsl:output method="xml" indent="yes" media-type="application/xml" 
              cdata-section-elements="Summary"/> 

   <!-- default: copy everything using the identity transform --> 
   <xsl:template match="@*|node()"> 
      <xsl:copy> 
         <xsl:apply-templates select="@*|node()"/> 
      </xsl:copy> 
   </xsl:template> 

   <!-- override: for Location and Salary nodes, just process the children --> 
   <xsl:template match="Location|Salary"> 
      <xsl:apply-templates select="node()"/> 
   </xsl:template> 

   <!-- override: for selected elements, convert attributes to elements --> 
   <xsl:template match="Jobs/@*|Job/@*"> 
      <xsl:element name="{name()}"> 
         <xsl:value-of select="."/> 
      </xsl:element> 
   </xsl:template> 

   <!-- override: for selected elements, remove attributes --> 
   <xsl:template match="DateActive/@*|DateExpires/@*|DateUpdated/@*"/> 
</xsl:stylesheet> 

Current Output in text is:

492 50 83000003 61999998 Market-leading company With a newly created role High Profile Position With Responsibilty, Visibility & Opportunity Must Have Solid BA Skills Honed in a SDLC environment Market-leading company With a newly created role High Profile Position With Responsibilty, Visibility & Opportunity Must Have Solid BA Skills Honed in a SDLC environment My client is a market-leader who continue to go from strengt 10/5/2009 11/4/2009 10/5/2009 Australia NSW Sydney 2000 Skill Quest 90,000.00 120,000.00 Per Year AUD 6

This outout i want in xml. pls help me to get a solution.


Do you have a line like this at the top of your XSLT file??

<xsl:output method="xml" indent="yes"/>

That defines what the output format is - "text" is default, "html" and "xml" are the other options.

I don't know what you're doing, but when I run your XSLT file on the sample XML file provided, I get this as output:

<?xml version="1.0" encoding="utf-8"?>
<root>
  <Jobs><Found>10</Found><Returned>50</Returned>
    <Job><ID>8000000</ID><PositionID>600002</PositionID>
      <Title>Development Manager</Title>
      <Summary>
         An experienced Development Manager with previous experience leading a small to mid-size team of developers in a Java/J2EE environment. A hands on role, you will be expected to manage and mentor a team of developers working on a mix of greenfield and maintenance projects.&amp;#160;&amp;#160; My client, a well known investment bank, requires an experienced Development Manager to join their core technology team. This t 

      </Summary>
      <DateActive>10/6/2009</DateActive>
      <DateExpires>11/5/2009</DateExpires>
      <DateUpdated>10/6/2009</DateUpdated>

        <Country>xxxx</Country>
        <State>xxx</State>
        <City>xxx</City>
        <PostalCode>xxx</PostalCode>

      <CompanyName>abc Technology</CompanyName>
      <BuilderFields />
      <DisplayOptions />
      <AddressType>1234</AddressType>
    </Job>
  </Jobs>
</root>

Marc


I suspect you are watching the transformation result in a browser.

The transformation itself works perfectly, but the browser displays the plain text of the XML (since it expects HTML contents by default and ignores any tags it does not recognize, displaying their text contents only).

Try media-type="text/xml" and see if that makes any difference. If it doesn't, don't let the browser display confuse you - there is nothing wrong with the XSLT. You should use another XSLT processor to confirm/debug the XSLT.


You probably write out the inner text of an xml node instead of calling apply-templates in one of your nodes. I couldn't find your attached xsl, so it's not easy to guess. But post the xslt, and I'll tell you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜