I have one alias file which is acting as a wraper to XML.

<Alias name='Type'>
<Xpath>@subType</Xpath>
</Alias>

generally this return MEConsumed or MEResource. I want the behaviour that if @subType=MEConsumed then it should return CON and when @subType=MEResource then it should return "REF".
Help me with this .. i am very new to all this

Regards,
Anish

if ()
    then expression 
  if (@subType=MEResource)
    then
  else expression

XPath has conditional statements, but XSLT might be easier to use since you only want to test two conditions. Then, you could use

<xsl:if test="{@subType=MEConsumed}">
  variableName="CON"
</xsl:if>
<xsl:if test="{@subType=MEResource}"
  variableName="REF"
</xsl>

Note, XSLT and XPath do not return statements like Java or other programming languages would. You'd want to set a variable and check it or set an attribute and check it.

Then again, their might be another way. Hope this helps even a little bit. :)

<Alias name='Type'>
<xsl:if test="{@subType=MEConsumed}">
variableName="CON"</xsl:if>
<xsl:if test="{@subType=MEResource}"
variableName="REF"</xsl>
</Alias>

on using this it throws an error::

The character '>' was expected. Error processing resource 'file://tc1016/New Folder/ME_FOLDER/Short-Term-Work/20_Anish/TcPu...

<xsl:if test="{@subType=MEConsumed}">
--------------^
Please guide

<Alias name='Type'>
<xsl:if test="{@subType=MEConsumed}">
    <xsl:variable name="testvar" value="CON" />
</xsl:if>
<xsl:if test="{@subType=MEResource}"[B]>[/B] <!--here is where > was missing-->
<xsl:variable name="testvar" value="REF" />
</xsl>
</Alias>

You need to create a variable
<xsl:variable name="ids" select="@ids" /> <!-- For instance -->
Initialize it, and then use that in place of "variableName/testVar." If you are calling a template, pass it using xsl:with-param and call it in the template as xsl:param. Here is a detailed description of xsl:param

Yes that missing > i already placed. Still problem remains unchanged. I think the problem is related to introduce XSL syntax in XPATH.

<xsl:variable name="ids" select="@subType"/>
<html>
<body>
<xsl:call-template name="TY">
<xsl:with-param name="ids" />
</xsl:call-template>
</body>
</html>
</xsl:variable>

<xsl:template match="TY">
<xsl:param name="ids" />
<xsl:choose>
<xsl:when test="starts-with($ids,'MEConsumed')">
<xsl:value-of select="'CON'"/>
</xsl:when>
<xsl:when test="starts-with($ids,'MEResource')">
<xsl:value-of select="'REF'"/>
</xsl:when>

<xsl:otherwise>

<xsl:value-of select="'NONE'"/>


</xsl:otherwise>
</xsl:choose>
</xsl:template>


Please help me asap.

SEE ATTACHMENT.

Search for " <xsl:call-template name="TY"> "

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.