Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reading a complex element from XML to XSL

 
Prashanth Chandra
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the below XML and I need to read the attribute "Overall Depth" from the XML file through an XSL file. I am not able to read the value in the XSL file for the condition check

<?xml version="1.0" encoding="UTF-8"?>
<Products xmlns:appliance="http://www.nonamespace/appliance" DateGenerated="06-02-2009 T08:12:21">
<Product ModelNumber="A3316ABSBB">
<DataSource Name="XCAT">
<AttributeGroups>
<AttributeGroup Name="WEIGHTS & DIMENSIONS">
<Attribute Name="Approximate Shipping Weight">163</Attribute>
<Attribute Name="Net Weight (lbs.)">144</Attribute>
<Attribute Name="Overall Height">61.75</Attribute>
<Attribute Name="Overall Width">28</Attribute>
<Attribute Name="Overall Depth">29.125</Attribute>
<Attribute Name="Case Depth Without Door (in.)">25-7/8</Attribute>
<Attribute Name="Depth with Door Open 90° (in.)">54-7/8</Attribute>
<Attribute Name="Depth Without Handle (in.)">29-1/8</Attribute>
<Attribute Name="Height to Mid-Freezer">51-3/8</Attribute>
<Attribute Name="Height to Top of Case (in.)">61-1/4</Attribute>
<Attribute Name="Width w/Door Open 90 Degrees Incl. Handle (in.)">30-1/2</Attribute>
<Attribute Name="Width w/Door Open 90 Degrees Less Handle (in.)">28-5/8</Attribute>
<Attribute Name="Back Air Clearances (in.)">1</Attribute>
<Attribute Name="Side Air Clearances (in.)">3/4</Attribute>
<Attribute Name="Top Air Clearances (in.)">1</Attribute>
</AttributeGroup>
</AttributeGroups>
</DataSource>
</Product>
</Products>


Below is my XSL file:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xalan="http://xml.apache.org/xslt"
xmlns:dyn="http://exslt.org/dynamic"
xmlns:date="http://exslt.org/dates-and-times"
xmlns:common="http://exslt.org/common"
xmlns:fn="http://functions"
xmlns:redirect="http://xml.apache.org/xalan/redirect"
extension-element-prefixes="xalan redirect fn dyn date"
version="1.0">

<xsl:import href="common-functions.xsl"/>
<xsl:variable name="mapping-file" select="'mapping/uccnet-mapping.xml'"/>
<xsl:variable name="attribute-mapping" select="document($mapping-file)/AttributeMappings" />


<xsl:variable name="model-file" select="'../trigger/inputxml/trigger.xml'"/>
<xsl:variable name="model-mapping" select="document($model-file)/Trigger/Products" />


<xsl:param name="delimiter" select="','"/>
<xsl:variable name = "marketGln">,marketGLN,publicationType</xsl:variable>

<xsl:param name="delivery-report-file"/>
<xsl:param name = "market_gln" />
<xsl:strip-space elements="*" />
<xslutput method="text"/>

<xsl:template match="/Products">
<xsl:variable name="filter-by-valid-sku"
select="Product[DataSource[@Name='XCAT']/BasicAttributes[Attribute[@Name='RELEASEDATE']!='' and
Attribute[@Name='DESCRIPTION']!='' and Attribute[@Name='UDEXCODE']!='']]"/>
<xsl:call-template name = "print-header"/>
<!-- Print Content -->
<xsl:for-each select = "$filter-by-valid-sku">

<xsl:variable name = "ModelNumber" select="$model-mapping/Product/SKU" />
<xsl:if test="@ModelNumber =$ModelNumber">
<xsl:if test="Product[DataSource[@Name='XCAT']/AttributeGroups/AttributeGroup[@Name='WEIGHTS & DIMENSIONS']/Attribute[@Name='Overall Depth']] !=''">

<xsl:call-template name="print-content">
<xsl:with-param name="aggr-sku-data" select="." />
</xsl:call-template>
</xsl:if>
</xsl:if>
</xsl:for-each>
</xsl:template>
<!-- Print Content -->
<xsl:template name = "print-header">
<xsl:for-each select="$attribute-mapping/Mapping">
<xsl:value-of select="normalize-space(@Name)"/>
<xsl:choose>
<xsl:when test = "position()!=last()">
<xsl:value-of select="$delimiter" />
</xsl:when>
<xsltherwise>
<xsl:value-of select="$marketGln" />
</xsltherwise>
</xsl:choose>
</xsl:for-each>
<xsl:text> </xsl:text>
</xsl:template>

<xsl:template name= "print-content">
<xsl:param name="aggr-sku-data" />
<xsl:for-each select="$attribute-mapping/Mapping">
<xsl:variable name="attribute-value">
<xsl:choose>

<xsl:when test="@source='hardcode'">
<xsl:value-of select="text()"/>
</xsl:when>
<xsltherwise>
<xsl:value-of select="dyn:evaluate(text())"/>
</xsltherwise>
</xsl:choose>
</xsl:variable>
<xsl:if test ="$attribute-value!=''">
<xsl:value-of select="normalize-space($attribute-value)"/>
</xsl:if>
<xsl:choose>
<xsl:when test = "position()!=last()">
<xsl:value-of select="$delimiter" />
</xsl:when>
<xsltherwise>
<xsl:text>,</xsl:text>
<xsl:value-of select="$market_gln"/>
<xsl:value-of select="$delimiter" />
</xsltherwise>
</xsl:choose>
</xsl:for-each>
<xsl:text> </xsl:text>
</xsl:template>
</xsl:stylesheet>

But I am not able to read the value in the XSL file for the condition check.

Thanks in advance
regards
Prashanth
 
Paul Clapham
Sheriff
Posts: 21305
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
BasicAttributes?
 
Prashanth Chandra
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have not copied the whole XML file as it is a very huge one. There is also an attribute for BasicAttributes in the XML and it is working fine when i am retrieving the values for it. I am not able to get the data for Over All Depth attribute.
 
Paul Clapham
Sheriff
Posts: 21305
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Prashanth Chandra wrote:I have not copied the whole XML file as it is a very huge one. There is also an attribute for BasicAttributes in the XML and it is working fine when i am retrieving the values for it.

Your XPath expression isn't looking for an attribute named BasicAttributes. It's looking for an element named BasicAttributes. But at any rate neither of those are present in the example you posted, and that's why the XPath expression would not find any nodes in that example.

However if you say the problem actually occurs with documents which do contain an attribute or element named BasicAttributes, then you should show us an example of that. Showing us an example of something else isn't helpful to anybody.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic