Unseen
Unseen

Reputation: 287

Exclude an xml node

I am stuck in something that probably for you might think is simple!

In an xml file I have these nodes

<Types>
  <Pas type="1" single="Man" plural="Men" />
  <Pas type="2" single="Woman" plural="Women" description="this is a test" />
  <Pas type="3" single="Child" plural="Children" description="this is another test" />
</Types>

Then in an xslt file a have javascript and I am filling a variable

Details = {<xsl:for-each select="/Types/Pas">"<xsl:value-of select="@type"/>": {single:"<xsl:value-of select="@single"/>",plural:"<xsl:value-of select="@plural"/>"}

So far so good. At some point in the xslt i have this

(<xsl:value-of select="$Details/@desc" />)* 

because i want to show the description in () with a * at the end.

And i am getting this:

Men()*
Women(this is a test)*
Children(this is another test)*

The problem is that i dont want the ()* in Men.

Is there any way to exclude it?

Regards!

Upvotes: 1

Views: 148

Answers (2)

FailedDev
FailedDev

Reputation: 26940

You just have to put this particular piece of code :

(<xsl:value-of select="$Details/@description" />)*

Into a conditional statement e.g.

<xsl:if test='current()/@description and string-length(current()/@description) > 0'>
  (<xsl:value-of select="$Details/@description" />)*
</xsl:if>

Note that this also takes care of empty attributes.

Upvotes: 1

ashansky
ashansky

Reputation: 730

You could add an xsl:if statement like this:

<xsl:if test="@description">
     (<xsl:value-of select="$Details/@desc" />)* 
</xsl:if>

Upvotes: 2

Related Questions