Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help with xsl for multiple child node

Status
Not open for further replies.

cli168

Programmer
Nov 20, 2006
10
US
We have the following data.
row meID EI

1_______a______________a1
_______________________a2
_______________________a3
_______________________a4
2_______b______________b1
_______________________b2
3_______c______________c1
_______________________c2

I would like to use XSL to display the data in the fashion:
<row=1>
__<meID>a</meID>
____<EI>a1</EI>
____<EI>a2</EI>
____<EI>a3</EI>
____<EI>a4</EI>
</row>
<row=2>
__<meID>b</meID>
____<EI>b1</EI>
____<EI>b2</EI>
</row>
<row=3>
__<meID>c</meID>
____<EI>c1</EI>
____<EI>c2</EI>
</row>

Currently, I am only able to get the XSL to lump all the EIs together:

<row=1>
__<meID>a</meID>
____<EI>a1a2a3a4</EI>
</row>

What do I need to change in the XSL to make it display 4 rows of EI?

Thanks.
 
What format is your data in? XSL is generally for transforming XML. Is your data in XML format? If so, please post an example of it.

Also, your desired output is not well-formed XML. Are the row numbers just for reference to the example? Do you want:

<row> or something like <row id="1">?

Jon

"I don't regret this, but I both rue and lament it.
 
What format is your data in?
>> Its in XML

XML before XSL:
++++++++
<?xml version = '1.0'?>
<ROWSET>
<ROW num="1">
<FS_FACILITYSITENAME>CSX Intermodal</FS_FACILITYSITENAME>
<ML_STFACILITYSYSTEMACRONYMNAME>FDM</ML_STFACILITYSYSTEMACRONYMNAME>
<EI_INFOSYSTEMACRONYMNAME>
<EI_INFOSYSTEMACRONYMNAME_ITEM>
<NEWATTRIB1>WAFR</NEWATTRIB1>
</EI_INFOSYSTEMACRONYMNAME_ITEM>
<EI_INFOSYSTEMACRONYMNAME_ITEM>
<NEWATTRIB1>WAFR</NEWATTRIB1>
</EI_INFOSYSTEMACRONYMNAME_ITEM>
<EI_INFOSYSTEMACRONYMNAME_ITEM>
<NEWATTRIB1>CHAZ</NEWATTRIB1>
</EI_INFOSYSTEMACRONYMNAME_ITEM>
</EI_INFOSYSTEMACRONYMNAME>
</ROW>
</ROWSET>
++++++++

XML after XSL
+++++++++
<?xml version = '1.0' encoding = 'UTF-8'?>
<Document Id="-----TRANSACTION-ID-----" xmlns=" xmlns:xsi=" xmlns:xsd=" <Payload Operation="Insert" xmlns="">
<FacilitySiteList xsi:schemaLocation=" schemaVersion="2.3" xmlns=" <FacilitySiteAllDetails>
<FacilitySite>
<FacilitySiteName>CSX Intermodal</FacilitySiteName>
</FacilitySite>
<EnvironmentalInterestDetails>
<InformationSystemAcronymName>WAFRWAFRCHAZ</InformationSystemAcronymName>
</EnvironmentalInterestDetails>
<SourceOfData/>
<LastReportedDate/>
</FacilitySiteAllDetails>
</FacilitySiteList>
</Payload>
</Document>
+++++++++

Ideally, I would like it to look like:
++++++++
<EnvironmentalInterestDetails>
<InformationSystemAcronymName>WAFR</InformationSystemAcronymName>
<InformationSystemAcronymName>WAFR</InformationSystemAcronymName>
<InformationSystemAcronymName>CHAZ</InformationSystemAcronymName>
</EnvironmentalInterestDetails>

++++++++

Thanks for your help!
 
Post you XSLT and we'll post a fix.

(Also, please learn to use the [ignore]
Code:
 ...
[/ignore] tag to better style your XML and XSLT.)

Tom Morrison
 
This should give you an idea:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform">[/URL]
  <xsl:template match="/">
    <Document>
      <Payload>
        <FacilitySiteList>
          <xsl:apply-templates select="ROWSET/ROW"/>
        </FacilitySiteList>
      </Payload>
    </Document>
  </xsl:template>
  <xsl:template match="ROW">
    <FacilitySiteAllDetails>
      <xsl:apply-templates/>
      <SourceOfData/>
      <LastReportedDate/>
    </FacilitySiteAllDetails>
  </xsl:template>
  <xsl:template match="FS_FACILITYSITENAME">
    <FacilitySite>
      <FacilitySiteName>
        <xsl:value-of select="."/>
      </FacilitySiteName>
    </FacilitySite>
  </xsl:template>
  <xsl:template match="ML_STFACILITYSYSTEMACRONYMNAME"/>
  <xsl:template match="EI_INFOSYSTEMACRONYMNAME">
    <EnvironmentalInterestDetails>
      <xsl:apply-templates/>
    </EnvironmentalInterestDetails>
  </xsl:template>
  <xsl:template match="EI_INFOSYSTEMACRONYMNAME_ITEM">
    <InformationSystemAcronymName>
      <xsl:value-of select="NEWATTRIB1"/>
    </InformationSystemAcronymName>
  </xsl:template>
</xsl:stylesheet>

Jon

"I don't regret this, but I both rue and lament it.
 
JontyMC,
Its working great. Thank-you.
Just one small question, how do I format it so that I have line breaks between elements:
<Document>
<Payload>

instead of <Document><Payload>

Also, can you recommend a good site that I can learn XSL?

Thanks.
 
cli168 said:
Just one small question, how do I format it so that I have line breaks between elements:
<Document>
<Payload>

instead of <Document><Payload>
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform"[/URL] xmlns:fo="[URL unfurl="true"]http://www.w3.org/1999/XSL/Format">[/URL]
  <xsl:output method="xml" indent="yes"/>
  .....

Jon

"I don't regret this, but I both rue and lament it.
 
I now have a need to have child nodes inside a child node.
I try the following but did not get anything:
+++++++++++++
<xsl:template match="ROW">
<FacilitySiteAllDetails>
<FacilitySite>
<xsl:apply-templates/>
</FacilitySite>
</FacilitySiteAllDetails>
</xsl:template>
<xsl:template match="FS_FACILITYSITENAME">
<FacilitySiteName>
<xsl:value-of select="."/>
</FacilitySiteName>
</xsl:template>
<xsl:template match="EI_GROUP">
<EnvironmentalInterestDetails>
<xsl:apply-templates/>
</EnvironmentalInterestDetails>
</xsl:template>
<xsl:template match="EI_GROUP_ITEM">
<InformationSystemAcronymName>
<xsl:value-of select="EI_INFOSYSTEMACRONYMNAME"/>
</InformationSystemAcronymName>
</xsl:template>
<xsl:template match="GE_GROUP">
<GeoLocationDetails>
<xsl:apply-templates/>
</GeoLocationDetails>
</xsl:template>
<xsl:template match="GE_GROUP_ITEM">
<GeoReferencePointText>
<xsl:value-of select="GE_REFERENCEPOINTTEXT"/>
</GeoReferencePointText>
</xsl:template>
+++++++++++++

Please, can you tell me what am I doing wrong?

Thanks.
 
Perhaps this? If GE_GROUP_ITEM is inside EI_GROUP_ITEM...
Code:
  <xsl:template match="EI_GROUP_ITEM">
    <InformationSystemAcronymName>
      <xsl:value-of select="EI_INFOSYSTEMACRONYMNAME"/>
      [COLOR=white red]<xsl:apply-templates/>[/color]
    </InformationSystemAcronymName>
  </xsl:template>

Without knowing the format of the input document with these new items, or the format of the desired output document, it is difficult to judge.

Tom Morrison
 
Yes, its always best to post the whole input doc, xsl and output doc.

<xsl:apply-templates/> means that templates are applied to the direct child nodes of the current context. The new nodes will only appear if they have something to match against.

Jon

"I don't regret this, but I both rue and lament it.
 
Here is the data:
+++++++++++++++++
<EI_GROUP>
<EI_GROUP_ITEM>
<EI_INFOSYSTEMACRONYMNAME>WAFR</EI_INFOSYSTEMACRONYMNAME>
<EI_ENVINTERESTSTARTDATE>2005-07-06</EI_ENVINTERESTSTARTDATE>
<EI_INTSTARTDATEQUALIFIERTEXT>Date of Permit Application</EI_INTSTARTDATEQUALIFIERTEXT>
<EI_INTENDDATEQUALIFIERTEXT>Date Operations Ended</EI_INTENDDATEQUALIFIERTEXT>
<NM_DATASOURCENAME>Permit Application</NM_DATASOURCENAME>
<SI_INFOSYSTEMACRONYMNAME>WAFR</SI_INFOSYSTEMACRONYMNAME>
<NI_INFOSYSTEMACRONYMNAME>WAFR</NI_INFOSYSTEMACRONYMNAME>
<GE_GROUPLIST>
<GE_GROUPLIST_ITEM>
<GE_REFERENCEPOINTTEXT>FACILITY CENTROID</GE_REFERENCEPOINTTEXT>
</GE_GROUPLIST_ITEM>
<GE_GROUPLIST_ITEM>
<GE_REFERENCEPOINTTEXT>FACILITY CENTROID</GE_REFERENCEPOINTTEXT>
</GE_GROUPLIST_ITEM>
</GE_GROUPLIST>
</EI_GROUP_ITEM>
</EI_GROUP>
+++++++++++++++++
 
Not sure what you want the output to be, but apply the suggestion in my previous post, and add a template similar to your others that will match GE_GROUPLIST_ITEM.

Tom Morrison
 
Also, closer investigation shows that your existing templates do not match GE_GROUPLIST (but you do have a template that matches apparently nonexistent GE_GROUP and GE_GROUP_ITEM).

Tom Morrison
 
Yes, swap

<xsl:template match="GE_GROUP">

with

<xsl:template match="GE_GROUPLIST">

and

<xsl:template match="GE_GROUP_ITEM">

with

<xsl:template match="GE_GROUPLIST_ITEM">

Jon

"I don't regret this, but I both rue and lament it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top