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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML to XML XSLT Transform when Attribute does not exist

Status
Not open for further replies.

coenen

Programmer
Dec 28, 2004
1
US
I am trying to do a XSLT transform from one XML format to another...so far everything is going very smooth except I am having some problems when I am doing concatination involving attributes. The problem is if say I am concatinating 3 attributes from one format into one value to be put in the new format, if any of the 3 attributes (all optional) are not included in the source xml file the entire concatination fails.

Is there a way around this? Even if one or more of the attributes do not exist in the source doc I still want it to concactinate what it can and just put nothing in the space where the missing attribute would be.

I'll try to make a simple example of files and guts of my concat.

Source
<Person Firstname="John" MiddleName="Jacob" LastName="JengleHiemerSchmitt"/>
<Person Firstname="Mary" LastName="Smith"/>

Target
<PersonFullName></PersonFullname>

XSLT concat
<PERSON>
<xsl:variable name="concatResult" select="concat('My Name is', $FirstName)"/>
<xsl:variable name="concatResult1" select="concat($concatResult, $MiddleName)"/>
<xsl:variable name="concatResult2" select="concat($concatResult1, $LastName)"/>
<xsl:value-of select="$concatResult2"/>
</PERSON>


For the first pperson it would work fine, but in the second person it would just give me nothing.

What am I doing wrong here?
 
Post your complete files, would be easier to work out what you doing wrong.

From what you got here, why not try:

Code:
<xsl:for-each select="Person">
  <PersonFullName>
    <xsl:value-of select="concat('My Name is ', @FirstName, ' ', @MiddleName, ' ', @LastName)"/>
  </PersonFullName>
</xsl:for-each>

Jon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top