wood burning stoves 2.0*
The moose likes XML and Related Technologies and the fly likes XML - CSV output format problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XML - CSV output format problem" Watch "XML - CSV output format problem" New topic
Author

XML - CSV output format problem

a thiti
Greenhorn

Joined: Aug 06, 2013
Posts: 5






Hi,

I have a task to convert XML file to CSV. The following is my XSLT

`<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:svg="http://www.w3.org/2000/svg" xmlns:rx="http://www.renderx.com/XSL/Extensions">
<xslutput method="text" version="1.0" encoding="UTF-8" indent="yes"/>

<xsl:strip-space elements="*" />

<xsl:template match="/*/child::*">

<xsl:for-each select="child::*">
<xsl:if test="position() != last()">"<xsl:value-of select="normalize-space(.)"/>", </xsl:if>
<xsl:if test="position() = last()">"<xsl:value-of select="normalize-space(.)"/>"<xsl:text> </xsl:text>
</xsl:if>
</xsl:for-each>

</xsl:template>

</xsl:stylesheet> `



And the input XML file is ...



`<?xml version = '1.0' encoding = 'UTF-8'?>
<DataElementsList>
<DataElement num="1">
<PUBLICID>2182882</PUBLICID>
<LONGNAME>Blood Pressure, Systolic</LONGNAME>
<PREFERREDNAME>BLD_PRESS_SYSTOLIC</PREFERREDNAME>
<PREFERREDDEFINITION>Indicating the maximum arterial pressure occurring during contraction of the left ventricle of the heart.</PREFERREDDEFINITION>
<VERSION>1</VERSION>
<WORKFLOWSTATUS>RELEASED</WORKFLOWSTATUS>
<CONTEXTNAME>DCP</CONTEXTNAME>
<CONTEXTVERSION>1</CONTEXTVERSION>
<ORIGIN NULL="TRUE"/>
<REGISTRATIONSTATUS>Qualified</REGISTRATIONSTATUS>
<DATAELEMENTCONCEPT>
<PublicId>2013135</PublicId>
<PreferredName>BP</PreferredName>
<PreferredDefinition>Measurement of the pressure of the BLOOD on the ARTERIES and other BLOOD VESSELS.</PreferredDefinition>
<LongName>Person Blood Pressure Assessment</LongName>
<Version>1</Version>
<WorkflowStatus>RELEASED</WorkflowStatus>
<ContextName>CCR</ContextName>
<ContextVersion>1</ContextVersion>
<ConceptualDomain>
<PublicId>2008551</PublicId>
<ContextName>CTEP</ContextName>
<ContextVersion>2.31</ContextVersion>
<PreferredName>ASSESS</PreferredName>
<Version>1</Version>
<LongName>Assessments</LongName>
</ConceptualDomain>
<ObjectClass>
<PublicId>2956127</PublicId>
<ContextName>NCI</ContextName>
<ContextVersion>1</ContextVersion>
<PreferredName>C25190:C54706</PreferredName>
<Version>1</Version>
<LongName>Person Blood Pressure</LongName>
<ConceptDetails>
<ConceptDetails_ITEM>
<PREFERRED_NAME>C25190</PREFERRED_NAME>
<LONG_NAME>Person</LONG_NAME>
<CON_ID>2202486</CON_ID>
<DEFINITION_SOURCE>NCI</DEFINITION_SOURCE>
<ORIGIN>NCI Thesaurus</ORIGIN>
<EVS_SOURCE>NCI_CONCEPT_CODE</EVS_SOURCE>
<PRIMARY_FLAG_IND>No</PRIMARY_FLAG_IND>
<DISPLAY_ORDER>1</DISPLAY_ORDER>
</ConceptDetails_ITEM>
<ConceptDetails_ITEM>
<PREFERRED_NAME>C54706</PREFERRED_NAME>
<LONG_NAME>Blood Pressure</LONG_NAME>
<CON_ID>2552352</CON_ID>
<DEFINITION_SOURCE>NCI</DEFINITION_SOURCE>
<ORIGIN>NCI Thesaurus</ORIGIN>
<EVS_SOURCE>NCI_CONCEPT_CODE</EVS_SOURCE>
<PRIMARY_FLAG_IND>Yes</PRIMARY_FLAG_IND>
<DISPLAY_ORDER>0</DISPLAY_ORDER>
</ConceptDetails_ITEM>
</ConceptDetails>
</ObjectClass>
<Property>
<PublicId>2233077</PublicId>
<ContextName>NCI</ContextName>
<ContextVersion>1</ContextVersion>
<PreferredName>C25367</PreferredName>
<Version>1</Version>
<LongName>Assessment</LongName>
<ConceptDetails>
<ConceptDetails_ITEM>
<PREFERRED_NAME>C25367</PREFERRED_NAME>
<LONG_NAME>Assessment</LONG_NAME>
<CON_ID>2203593</CON_ID>
<DEFINITION_SOURCE>NCI</DEFINITION_SOURCE>
<ORIGIN>NCI Thesaurus</ORIGIN>
<EVS_SOURCE>NCI_CONCEPT_CODE</EVS_SOURCE>
<PRIMARY_FLAG_IND>Yes</PRIMARY_FLAG_IND>
<DISPLAY_ORDER>0</DISPLAY_ORDER>
</ConceptDetails_ITEM>
</ConceptDetails>
</Property>
<ObjectClassQualifier NULL="TRUE"/>
<PropertyQualifier NULL="TRUE"/>
<Origin NULL="TRUE"/>
</DATAELEMENTCONCEPT>

</DataElement>
<DataElementsList> `


Once I ran transformation, everything seemed to be fine for the first level, but when it reached to nested tag "PublicId". All values got mix together. Please see output below.

"2182882","Blood Pressure, Systolic","BLD_PRESS_SYSTOLIC","Indicating the maximum arterial pressure occurring during contraction of the left ventricle of the heart.","1","RELEASED","DCP","1","","Qualified","2013135BPMeasurement of the pressure of the BLOOD on the ARTERIES and other BLOOD VESSELS.Person Blood Pressure Assessment1RELEASEDCCR12008551CTEP2.31ASSESS1Assessments2956127NCI1C25190:C547061Person Blood PressureC25190Person2202486NCINCI ThesaurusNCI_CONCEPT_CODENo1C54706Blood Pressure2552352NCINCI ThesaurusNCI_CONCEPT_CODEYes02233077NCI1C253671AssessmentC25367Assessment2203593NCINCI ThesaurusNCI_CONCEPT_CODEYes0","2182880BLOOD_PRESSURE_SYSTOLICIndicating the maximum arterial pressure occurring during contraction of the left ventricle of the heart.Blood Pressure, Systolic3RELEASEDDCP12008514DCP1DCP1DCP Conceptual DomainNUMBERNonEnumeratedmmHg82233101NCI1C253371NumberC25337Number2202701Source => Name: NCI, NCI ThesaurusNCI_CONCEPT_CODEYes0","Blood Pressure, SystolicPreferred Question TextBlood Pressure, SystolicENGLISH","2194255DCP1Condition1Subclinical Neoplastic LesionsDISEASE_TYPE281251612194255DCP1Condition1Budesonide Lung NodulesDISEASE_TYPE281210212194255DCP1Condition1SAMe - Hepatitis C cirrhosisDISEASE_TYPE281214812194255DCP1Condition1Pancreatic Mucinous NeoplasmsDISEASE_TYPE281214912194255DCP1Condition1Prostate - LycopeneDISEASE_TYPE281215112194255DCP1Condition1Barretts Esophagus - ASA-EsomeprazoleDISEASE_TYPE281215212194255DCP1Condition1Bronchial Dysplasia - SulindacDISEASE_TYPE281215412194255DCP1Condition1Sporadic Colorectal Neoplasia - AtrovastatinDISEASE_TYPE281215512194255DCP1Condition1Melanoma Pathobiology - LovastatinDISEASE_TYPE281215712194255DCP1Condition1Polyphenon E - Hormone Receptor-Negative Breast CancerDISEASE_TYPE281217412194255DCP1Condition1Safety Study of Resiquimod for Atyical NeviDISEASE_TYPE281217712194255DCP1Condition1Tissue Effect of Finasteride - Prostate CancerDISEASE_TYPE281218212194255DCP1Condition1Atrovastatin in Women at High Risk for Breast CancerDISEASE_TYPE281218312194255DCP1Condition1Spectral Markers in ASADISEASE_TYPE281218412194255DCP1Condition1Se-Methyl-Seleno-L-Cystein (MSC) in Adult MenDISEASE_TYPE281218812194255DCP1Condition1Polyphenon E - Pre-prostatectomy Prostate CancerDISEASE_TYPE281218912194255DCP1Condition1Acolbifene - High Risk for Breast CancerDISEASE_TYPE281219012194255DCP1Condition1ALA PDT - Oral LeukoplakiaDISEASE_TYPE281219412194255DCP1Condition1DIM - Prostate CancerDISEASE_TYPE281220212194255DCP1Condition1Aminolevulinic Acid - Barrett's EsophagusDISEASE_TYPE281227712194255DCP1Condition1Drug and Carcinogen Enzymes - ResveratrolDISEASE_TYPE281225812194255DCP1Condition1Polyphenon E - Bladder CancerDISEASE_TYPE281253912194255DCP1Condition19cUAB30DISEASE_TYPE281255112194255DCP1Condition1EGF Receptor Signaling in ACFDISEASE_TYPE281255312194255DCP1Condition1PK and Safety - Novel Retinoid (9cUAB30)TRIAL_TYPE_USAGE281276812194255DCP1Condition1Imiquimod for Atypical NeviDISEASE_TYPE281283612194255DCP1Condition1Polyethylene Glycol - Colon CarcinogenesisTRIAL_TYPE_USAGE281284312194255DCP1Condition1Bronchial Dysplasia - Myo-InositolTRIAL_TYPE_USAGE281287612194255DCP1Condition1Exp. PK Formulations of SR13668TRIAL_TYPE_USAGE281294912194255DCP1Condition13, 3-Diindolylmethane Cervical IntraepithelialTRIAL_TYPE_USAGE281273512194255DCP1Condition1Transdermal 4-OHT vs oral TAM DCIS of the BreastTRIAL_TYPE_USAGE281273612194255DCP1Condition1Pioglitazone - Oral LeukoplakiaDISEASE_TYPE281299812194255DCP1Condition1Sulindac - Increased Risk of MelanomaDISEASE_TYPE281300212194255DCP1Condition1Ursodeoxycholic Acid - Barrett's PatientsTRIAL_TYPE_USAGE281304312194255DCP1Condition1Erlotinib - Lesions of LungCase Report Form281306412179692DCP1Category1Case Report Forms Version 3Case Report Form295737212194255DCP1Condition1Letrozole - Breast CancerTRIAL_TYPE_USAGE284276812194255DCP1Condition1Breast Sulindac DFMOTRIAL_TYPE_USAGE285962812194255DCP1Condition1Polyphenon E in Women w/ Modulation of Arachidonic AcidTRIAL_TYPE_USAGE293651812194255DCP1Condition1MyoInositol Chemoprevention in Colitis-Assoc. DysplasiaTRIAL_TYPE_USAGE297917212194255DCP1Condition1Metformin Colorectal CancerTRIAL_TYPE_USAGE301878112194255DCP1Condition1Resveratrol in Postmenopausal WomenTRIAL_TYPE_USAGE301878212194255DCP1Condition1MSC and L SeMet in Adult MenDISEASE_TYPE311021912194255DCP1Condition1Cholecalciferol and GenisteinDISEASE_TYPE311416312194255DCP1Condition1Pioglitazone - Lung Pre-Surgical NSCLCTRIAL_TYPE_USAGE315282012194255DCP1Condition1Vitamin D - Bioactivity in the SkinTRIAL_TYPE_USAGE318287812194255DCP1Condition1Metformin - Pre-Prostatectomy Prostate CancerTRIAL_TYPE_USAGE318287912194255DCP1Condition1Barrett's Esophagus Chemoprevention MetforminTRIAL_TYPE_USAGE321179212194255DCP1Condition1PARP Inhibitor - ABT-888TRIAL_TYPE_USAGE321951712179692DCP1Category1Case Report FormsCase Report Form281173412194255DCP1Condition1Barretts EsophagusDISEASE_TYPE281236412194255DCP1Condition1Bladder CancerDISEASE_TYPE281237712194255DCP1Condition1Oral LeukoplakiaDISEASE_TYPE281238812194255DCP1Condition1Polyphenon E for Cervical CaDISEASE_TYPE281239912194255DCP1Condition1Sulindac for Breast CancerDISEASE_TYPE281241512194255DCP1Condition1Unconjugated Isoflavones in Women at High Risk for Breast CancerDISEASE_TYPE28125021","DCP1ENGLISHCONTEXT NAMEENGLISH","COMPOUNDconcept derivation rule with multiple conceptsCombines Blood Pressure, Systolic 2182882 with Alpha DVG BPS 2183219 that could be used for Oracle Clinical."



I have tried to modify the XSLT but I just don't know what I am doing.

Any help will be very appreciated.

Thank you
a thiti
Greenhorn

Joined: Aug 06, 2013
Posts: 5
I got it resolved.

My XSLT was too generic. I wrote a new one like this


<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:svg="http://www.w3.org/2000/svg" xmlns:rx="http://www.renderx.com/XSL/Extensions">
<xslutput method="text" version="1.0" encoding="UTF-8" indent="yes"/>

<xsl:param name="delim" select="','" />
<xsl:param name="quote" select="'"'" />
<xsl:param name="break" select="' '" />

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

<xsl:template match="DataElement">
<xsl:apply-templates />
<xsl:if test="following-sibling::*">
<xsl:value-of select="$break" />
</xsl:if>
</xsl:template>

<xsl:template match="*" >
<!-- remove normalize-space() if you want keep white-space at it is -->
<xsl:value-of select="concat($quote, normalize-space(), $quote)" />
<xsl:if test="following-sibling::*">
<xsl:value-of select="$delim" />
</xsl:if>
</xsl:template>


<xsl:template match="/DataElementsList/DataElement/DATAELEMENTCONCEPT">
<xsl:apply-templates />
<xsl:if test="following-sibling::*">
<xsl:value-of select="$break" />
</xsl:if>
</xsl:template>

<xsl:template match="*" >
<!-- remove normalize-space() if you want keep white-space at it is -->
<xsl:value-of select="concat($quote, normalize-space(), $quote)" />
<xsl:if test="following-sibling::*">
<xsl:value-of select="$delim" />
</xsl:if>
</xsl:template>

<xsl:template match="/DataElementsList/DataElement/DATAELEMENTCONCEPT/ConceptualDomain">
<xsl:apply-templates />
<xsl:if test="following-sibling::*">
<xsl:value-of select="$break" />
</xsl:if>
</xsl:template>

<xsl:template match="*" >
<!-- remove normalize-space() if you want keep white-space at it is -->
<xsl:value-of select="concat($quote, normalize-space(), $quote)" />
<xsl:if test="following-sibling::*">
<xsl:value-of select="$delim" />
</xsl:if>
</xsl:template>

<xsl:template match="/DataElementsList/DataElement/DATAELEMENTCONCEPT/ConceptualDomain">
<xsl:apply-templates />
<xsl:if test="following-sibling::*">
<xsl:value-of select="$break" />
</xsl:if>
</xsl:template>

<xsl:template match="*" >
<!-- remove normalize-space() if you want keep white-space at it is -->
<xsl:value-of select="concat($quote, normalize-space(), $quote)" />
<xsl:if test="following-sibling::*">
<xsl:value-of select="$delim" />
</xsl:if>
</xsl:template>


<xsl:template match="/DataElementsList/DataElement/DATAELEMENTCONCEPT/ObjectClass">
<xsl:apply-templates />
<xsl:if test="following-sibling::*">
<xsl:value-of select="$break" />
</xsl:if>
</xsl:template>

<xsl:template match="*" >
<!-- remove normalize-space() if you want keep white-space at it is -->
<xsl:value-of select="concat($quote, normalize-space(), $quote)" />
<xsl:if test="following-sibling::*">
<xsl:value-of select="$delim" />
</xsl:if>
</xsl:template>


<xsl:template match="/DataElementsList/DataElement/DATAELEMENTCONCEPT/ObjectClass/ConceptDetails/ConceptDetails_ITEM ">
<xsl:apply-templates />
<xsl:if test="following-sibling::*">
<xsl:value-of select="$break" />
</xsl:if>
</xsl:template>

<xsl:template match="*" >
<!-- remove normalize-space() if you want keep white-space at it is -->
<xsl:value-of select="concat($quote, normalize-space(), $quote)" />
<xsl:if test="following-sibling::*">
<xsl:value-of select="$delim" />
</xsl:if>
</xsl:template>

<xsl:template match="/DataElementsList/DataElement/DATAELEMENTCONCEPT/Property">
<xsl:apply-templates />
<xsl:if test="following-sibling::*">
<xsl:value-of select="$break" />
</xsl:if>
</xsl:template>

<xsl:template match="*" >
<!-- remove normalize-space() if you want keep white-space at it is -->
<xsl:value-of select="concat($quote, normalize-space(), $quote)" />
<xsl:if test="following-sibling::*">
<xsl:value-of select="$delim" />
</xsl:if>
</xsl:template>


<xsl:template match="text()" />







</xsl:stylesheet>
g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 499
    
    3
Every time you find yourself needing this:
<xsl:template match="text()" />

You have not made sufficient control on the progression of template matching, such as your using this that has an appearence quite innocent
<xsl:apply-templates />
a thiti
Greenhorn

Joined: Aug 06, 2013
Posts: 5
What you mean by "innocent"? Please do tell.
g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 499
    
    3
http://oxforddictionaries.com/definition/english/innocent
4. not involving or intended to cause harm or offence; harmless:an innocent mistake.

If you don't find any problem at all, that's fine for me.
a thiti
Greenhorn

Joined: Aug 06, 2013
Posts: 5
Thank you for your response.

That <xsl:template match="text()" /> tag was working for me. If I take it off, the layout will be not I expect.

Now, I am facing another issue. Hopefully you can guide me to the right direction.

So far my XSLT is like this...

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:svg="http://www.w3.org/2000/svg" xmlns:rx="http://www.renderx.com/XSL/Extensions">
<xslutput method="text" version="1.0" encoding="UTF-8" indent="yes"/>

<xsl:param name="delim" select="','" />
<xsl:param name="quote" select="'"'" />
<xsl:param name="break" select="' '" />

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


<xsl:template match="/DataElementsList/DataElement">
<xsl:apply-templates />
<xsl:if test="following-sibling::*">
<xsl:value-of select="$break" />
</xsl:if>
</xsl:template>

<xsl:template match="*" >
<!-- remove normalize-space() if you want keep white-space at it is -->
<xsl:value-of select="concat($quote, normalize-space(), $quote)" />
<xsl:if test="following-sibling::*">
<xsl:value-of select="$delim" />
</xsl:if>
</xsl:template>


<xsl:template match="/DataElementsList/DataElement/DATAELEMENTCONCEPT">
<xsl:apply-templates />
<xsl:if test="following-sibling::*">
<xsl:value-of select="$break" />
</xsl:if>
</xsl:template>

<xsl:template match="*" >
<!-- remove normalize-space() if you want keep white-space at it is -->
<xsl:value-of select="concat($quote, normalize-space(), $quote)" />
<xsl:if test="following-sibling::*">
<xsl:value-of select="$delim" />
</xsl:if>
</xsl:template>

<xsl:template match="/DataElementsList/DataElement/DATAELEMENTCONCEPT/ConceptualDomain">
<xsl:apply-templates />
<xsl:if test="following-sibling::*">
<xsl:value-of select="$break" />
</xsl:if>
</xsl:template>

<xsl:template match="*" >
<!-- remove normalize-space() if you want keep white-space at it is -->
<xsl:value-of select="concat($quote, normalize-space(), $quote)" />
<xsl:if test="following-sibling::*">
<xsl:value-of select="$delim" />
</xsl:if>
</xsl:template>




<xsl:template match="/DataElementsList/DataElement/DATAELEMENTCONCEPT/ObjectClass">
<xsl:apply-templates />
<xsl:if test="following-sibling::*">
<xsl:value-of select="$break" />
</xsl:if>
</xsl:template>

<xsl:template match="*" >
<!-- remove normalize-space() if you want keep white-space at it is -->
<xsl:value-of select="concat($quote, normalize-space(), $quote)" />
<xsl:if test="following-sibling::*">
<xsl:value-of select="$delim" />
</xsl:if>
</xsl:template>


<xsl:template match="/DataElementsList/DataElement/DATAELEMENTCONCEPT/ObjectClass/ConceptDetails/ConceptDetails_ITEM">
<xsl:apply-templates />

<xsl:if test="following-sibling::*">
<xsl:value-of select="$break" />
</xsl:if>

</xsl:template>

<xsl:template match="*" >
<!-- remove normalize-space() if you want keep white-space at it is -->
<xsl:value-of select="concat($quote, normalize-space(), $quote)" />
<xsl:if test="following-sibling::*">
<xsl:value-of select="$delim" />
</xsl:if>
</xsl:template>

<xsl:template match="/DataElementsList/DataElement/DATAELEMENTCONCEPT/Property">
<xsl:apply-templates />
<xsl:if test="following-sibling::*">
<xsl:value-of select="$break" />
</xsl:if>
</xsl:template>

<xsl:template match="*" >
<!-- remove normalize-space() if you want keep white-space at it is -->
<xsl:value-of select="concat($quote, normalize-space(), $quote)" />
<xsl:if test="following-sibling::*">
<xsl:value-of select="$delim" />
</xsl:if>
</xsl:template>





<xsl:template match="text()" />


</xsl:stylesheet>


Please see the red color for my XSLT.

Once I run the transformation, I got the same problem. ( Please see this following output (red color)).

"2182882","Blood Pressure, Systolic","BLD_PRESS_SYSTOLIC","Indicating the maximum arterial pressure occurring during contraction of the left ventricle of the heart.","1","RELEASED","DCP","1","","Qualified","2013135","BP","Measurement of the pressure of the BLOOD on the ARTERIES and other BLOOD VESSELS.","Person Blood Pressure Assessment","1","RELEASED","CCR","1","2008551","CTEP","2.31","ASSESS","1","Assessments"
"2956127","NCI","1","C25190:C54706","1","Person Blood Pressure","C25190 Person 2202486 NCI NCI Thesaurus NCI_CONCEPT_CODE No 1 C54706 Blood Pressure 2552352 NCI NCI Thesaurus NCI_CONCEPT_CODE Yes 0"
"2233077","NCI","1","C25367","1","Assessment","C25367 Assessment 2203593 NCI NCI Thesaurus NCI_CONCEPT_CODE Yes 0"
"","",""

It behave the same way just like the first problem.

I would like to ask for your expertise how to fix them to follow the rest.

Thank you,
g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 499
    
    3
[1] Take out the template meaning eliminate it all together.
<xsl:template match="text()" />


[2] Take out all duplicate template matching "*" leaving only one in. They are all the same and only one is enough.

[3] Change all the matching to elements by leaving only the last element name except the first template (see 3.2).

[3.1] For instance this
<xsl:template match="/DataElementsList/DataElement/DATAELEMENTCONCEPT">

Change it to this.


[3.2] Change the first to this, though functionally same but important conceptually consistent.


[4] Change all apply-templates which does not have select attribute:
<xsl:apply-templates />

to this


[5] Review carefully your parameters: there seems to have some syntax errors there. (But that can be an artifact of this forum rendering machine.)

The above till this moment. Test it out first. I'll see if I have more advices until I see what happen.
a thiti
Greenhorn

Joined: Aug 06, 2013
Posts: 5
THANK YOU SO MUCH!

I followed your advice and was able to cleanup some mistake. My XSLT look alot cleaner.

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:svg="http://www.w3.org/2000/svg" xmlns:rx="http://www.renderx.com/XSL/Extensions">
<xslutput method="text" version="1.0" encoding="UTF-8" indent="yes"/>

<xsl:param name="delim" select="','" />
<xsl:param name="quote" select="'"'" />
<xsl:param name="break" select="' '" />


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


<xsl:template match="DataElement">
<xsl:apply-templates select="*" />
<xsl:if test="following-sibling::*">
<xsl:value-of select="$break" />
</xsl:if>
</xsl:template>



<xsl:template match="ConceptualDomain">
<xsl:apply-templates select="*" />
<xsl:if test="following-sibling::*">
<xsl:value-of select="$break" />
</xsl:if>
</xsl:template>


<xsl:template match="ObjectClass">
<xsl:apply-templates select="*" />
<xsl:if test="following-sibling::*">
<xsl:value-of select="$break" />
</xsl:if>
</xsl:template>





<xsl:template match="*" >
<xsl:apply-templates select="*" />
<!-- remove normalize-space() if you want keep white-space at it is -->
<xsl:value-of select="concat($quote, normalize-space(), $quote)" />
<xsl:if test="following-sibling::*">
<xsl:value-of select="$delim" />
</xsl:if>
</xsl:template>


<xsl:template match="text()" />


</xsl:stylesheet>


The element bundling problem now has been gone.

I am having another problem. The output elements especially the one which are generated from 3 or 4 levels below their parent elements sometime repeat them self ( please see output below ). It start good and end with duplicate values which got bundled together.


"C25190***","Person","2202486","NCI","NCI Thesaurus","NCI_CONCEPT_CODE","No","1""C25190*** Person 2202486 NCI NCI Thesaurus NCI_CONCEPT_CODE No 1",


I tried to add piece by piece but cannot solve this problem.
g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 499
    
    3
I don't necessarily understand why you need a break after DataElement, ConceptualDomain and ObjectClass... putting them on equal basis in this regard. They are of different depth in the document. I leave it to you for the proper interpretation semantic of the document and take it as such.

Also, I don't see already the need of suppressing the default built-in template for text(). That action is no longer needed after proper control in the xsl:apply-templates.

Now, the apparent problem of duplicate text added to the output. That is due to the defective template matching element wildcard. You can remedy it like this.


If you can confirm the output being what you desired, I could suggest a more radical surgery to make the template structure even more rational. But that's for a later stage.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: XML - CSV output format problem
 
Similar Threads
Teas
Will you go to Iraq ?
How long did they take to correct your assignment?
WA #1.....word association
Pie