FirDaus
FirDaus

Reputation: 1

XSLT translation from XML

I would like to do a XSLT translation to find a certain value using a condition.

My XML files snippet as below:

   <?xml version="1.0" encoding="utf-8"?>
    <?xml-stylesheet type="text/xsl" href="sample.xslt"?>

<ValuesList>
    <Values ID="ZLOV1FD23146" ParentID="ZLOV1GR00001" AllowUserValueAddition="true" UseValueID="false">
      <Name QualifierID="std.lang.all">MG1_01 USP [MPRD]</Name>
      <Validation BaseType="text" MinValue="" MaxValue="" MaxLength="511" InputMask=""/>
      <Language DimensionID="Language"/>   
      <ValueGroup>
        <Value QualifierID="lang_ZPIM1ID">ABC</Value>
        <Value QualifierID="std.lang.all">minimised recess depth enables use in   ceilings with compact space</Value>
      </ValueGroup>
      <ValueGroup>
        <Value QualifierID="std.lang.all">DEF</Value>
      </ValueGroup>
      <ValueGroup>
        <Value QualifierID="lang_ZPIM1ID">ASD</Value>
        <Value QualifierID="std.lang.all">qwer</Value>
      </ValueGroup>
      <ValueGroup>
        <Value QualifierID="std.lang.all">FGH</Value>
        <Value QualifierID="lang_ZPIM1ID">dfghy</Value>
      </ValueGroup>
      <ValueGroup>
        <Value QualifierID="std.lang.all">RST</Value>
      </ValueGroup>   
    </Values>

    <Values ID="ZLOV1FDsdasda" ParentID="ZLOV1GR00002" AllowUserValueAddition="true" UseValueID="false">
      <Name QualifierID="std.lang.all">MG1_01 USP [MPRD]</Name>
      <Validation BaseType="text" MinValue="" MaxValue="" MaxLength="511" InputMask=""/>
      <Language DimensionID="Language"/>    
      <ValueGroup>
        <Value QualifierID="lang_ZPIM1ID">ABC</Value>
        <Value QualifierID="std.lang.all">minimised recess depth enables use in   ceilings with compact space</Value>
      </ValueGroup>
      <ValueGroup>
        <Value QualifierID="std.lang.all">asdas</Value>
      </ValueGroup>
      <ValueGroup>
        <Value QualifierID="lang_ZPIM1ID">ASD</Value>
        <Value QualifierID="std.lang.all">qwer</Value>
      </ValueGroup>
      <ValueGroup>
        <Value QualifierID="std.lang.all">FGH</Value>
        <Value QualifierID="lang_ZPIM1ID">dfghy</Value>
      </ValueGroup>
      <ValueGroup>
        <Value QualifierID="std.lang.all">iyi</Value>
      </ValueGroup>
    </Values>
</ValuesList>

I need to create sample.XSLT file in order to meet below conditions:

I have created the XSLT file as below snippet but does not work:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="text" indent="yes"/>
    <xsl:strip-space elements="*"/>       
    <xsl:template match="ValuesList/Values/ValueGroup">
            <xsl:text> ID       | Value</xsl:text>
            <xsl:text>&#x0A;</xsl:text>
        <xsl:if test="count(Value)='1' and Value/@QualifierID='std.lang.all'">          
                <xsl:value-of select="concat(//Values/@ID,'  |',Value,'&#x0A;')"></xsl:value-of>
        </xsl:if>
    </xsl:template>
</xsl:stylesheet>

Kindly help me out..Thanks in advance.

Upvotes: 0

Views: 171

Answers (1)

Joel M. Lamsen
Joel M. Lamsen

Reputation: 7173

you can have something like this:

EDITED

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="text" indent="yes"/>
    <xsl:strip-space elements="*"/>       

    <xsl:template match="/">
        <xsl:text> ID       | Value</xsl:text>
        <xsl:text>&#x0A;</xsl:text>
        <!-- Choose the nodes you want to output here.
             you can directly place the conditions
             in an attribute -->
        <xsl:apply-templates select="ValuesList/Values[Language[@DimensionID='Language']]"/>
    </xsl:template>

    <xsl:template match="Values">
        <xsl:apply-templates select="ValueGroup[count(Value)=1 and Value/@QualifierID='std.lang.all']"/>
    </xsl:template>

    <xsl:template match="ValueGroup">
        <xsl:value-of select="concat(ancestor::Values/@ID,'  |',Value,'&#x0A;')"/>
    </xsl:template>

</xsl:stylesheet>

Upvotes: 1

Related Questions