XSLT only output part of a node in certain conditions

MrGreenPower

New Member
I often get some XML that isn't formatted as I'm expecting it to be, and am looking for the best way to automatically fix it. Unfortunately, the solution is skating over my head.I'm working on magazine content, and having difficult with two specific elements.\[code\]There are <subhead> elements, and <body> elements. Even though the subhead element should always be on it's own, sometimes the proofer will accidentally nest it with a <body> node.<subhead> nodes should be formatted as their own paragraph, wrapped in <p> and <strong> tags.<body> nodes should just be wrapped in <p> tags.So I could get either:<subhead>Dogs</subhead><body>Dogs do not like cats.</body>or<body><subhead>Dogs</subhead> Dogs do not like cats.</body>I would like either scenario to output as:<p><strong>Dogs</strong></p><p>Dogs do not like cats.</p>\[/code\]Currently, my code looks like..\[code\]<xsl:for-each select="//default:textObject/default:text/*"><xsl:for-each select="./*"><xsl:choose><xsl:when test="@name='subhead'"><p><strong><xsl:apply-templates select="node()"/></strong></p></xsl:when><xsl:when test="@name='body'"><p><xsl:apply-templates select="node()"/></p></xsl:when>...</xsl:choose></xsl:for-each></xsl:for-each>\[/code\]How can I adjust this accordingly to solve that problem?Thank you.
 
Back
Top