Jump to content

Search the Community

Showing results for tags 'xslt 1.0'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • W3Schools
    • General
    • Suggestions
    • Critiques
  • HTML Forums
    • HTML/XHTML
    • CSS
  • Browser Scripting
    • JavaScript
    • VBScript
  • Server Scripting
    • Web Servers
    • Version Control
    • SQL
    • ASP
    • PHP
    • .NET
    • ColdFusion
    • Java/JSP/J2EE
    • CGI
  • XML Forums
    • XML
    • XSLT/XSL-FO
    • Schema
    • Web Services
  • Multimedia
    • Multimedia
    • FLASH

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Languages

Found 2 results

  1. Hi, I am not a developer, but I have to deal with xslt to format xml and generate pdfs occasionally for work. below you can see the XML and the XSL I am trying to format it with. It all worked fine until I tried to insert the second template. Obviously I am doing something wrong. I am trying to use template and for-each to add a row in the table for each <order_line_item> nested under <order_line_items> and in each of the four cells there should be the four values nested under <order_line_item> Could you help? Thanks! I was told that you cannot nest templates, so obviously that needs correction. Could someone provide a worked out solution please? XML <hash> <order_line_items type="array"> <order_line_item> <document_currency_unit_price_after_discount_value amount="300.0" code="GBP">£300.00</document_currency_unit_price_after_discount_value> <document_currency_net_after_main_discount amount="300.0" code="GBP">£300.00</document_currency_net_after_main_discount> <description>Subscription</description> <unit_quantity type="decimal">1.0</unit_quantity> </order_line_item> <order_line_item> <document_currency_unit_price_after_discount_value amount="300.0" code="GBP">£200.00</document_currency_unit_price_after_discount_value> <document_currency_net_after_main_discount amount="300.0" code="GBP">£200.00</document_currency_net_after_main_discount> <description>Additional Services</description> <unit_quantity type="decimal">1.0</unit_quantity> </order_line_item> <order_line_item> <document_currency_unit_price_after_discount_value amount="300.0" code="GBP">£-50.00</document_currency_unit_price_after_discount_value> <document_currency_net_after_main_discount amount="300.0" code="GBP">£-50.00</document_currency_net_after_main_discount> <description>Discount</description> <unit_quantity type="decimal">1.0</unit_quantity> </order_line_item> </order_line_items> </hash> XSL <fo:table margin-bottom="5mm"> <fo:table-column column-width="25%"/> <fo:table-column column-width="25%"/> <fo:table-column column-width="25%"/> <fo:table-column column-width="25%"/> <fo:table-body> <fo:table-row> <fo:table-cell> <fo:block> Product </fo:block> </fo:table-cell> <fo:table-cell> <fo:block> Quantity </fo:block> </fo:table-cell> <fo:table-cell> <fo:block> Unit Price </fo:block> </fo:table-cell> <fo:table-cell> <fo:block> Net Amount </fo:block> </fo:table-cell> </fo:table-row> <xsl:template match="hash/order_line_items"> <xsl:for-each select="order_line_item"> <fo:table-row> <fo:table-cell> <fo:block> <xsl:value-of select="description"> </fo:block> </fo:table-cell> <fo:table-cell> <fo:block> <xsl:value-of select="document_currency_unit_price_after_discount_value"> </fo:block> </fo:table-cell> <fo:table-cell> <fo:block> <xsl:value-of select="document_currency_net_after_main_discount"> </fo:block> </fo:table-cell> <fo:table-cell> <fo:block> <xsl:value-of select="unit_quantity"> </fo:block> </fo:table-cell> </fo:table-row> </xsl:for-each> </xsl:template> </fo:table-body> </fo:table> </fo:flow> </fo:page-sequence> </fo:root> </xsl:template> </xslt:stylesheet>
  2. Hello, I have created one XSLT which is transforming one XML to another XML. Sample XML. <Answers> <AnswerSet ID="1142"> <Answer questionId="Name">testttttt123</Answer> <Answer questionId="TesCal">1/26/2012 12:00:00 AM</Answer> <Answer questionId="testPhoto" IsProcessed="True">Node1216sadi20120113.JPG</Answer> <Answer questionId="Testrr" RepeatRegion="0" RegionName="Sam">rr111</Answer> <Answer questionId="Testrr1" RepeatRegion="0" RegionName="Sam">123456</Answer> <Answer questionId="Testrr" RepeatRegion="1" RegionName="Sam">rr1112</Answer> <Answer questionId="Testrr1" RepeatRegion="1" RegionName="Sam">456789</Answer> <Answer questionId="Testrr" RepeatRegion="2" RegionName="Sam">rr1113</Answer> <Answer questionId="Testrr1" RepeatRegion="2" RegionName="Sam">4577855</Answer> <Answer questionId="Testrr" RepeatRegion="3" RegionName="Sam" /> <Answer questionId="Testrr1" RepeatRegion="3" RegionName="Sam" /> <Answer questionId="Testrr" RepeatRegion="4" RegionName="Sam" /> <Answer questionId="Testrr1" RepeatRegion="4" RegionName="Sam" /> <Answer questionId="testPhoto12" IsProcessed="True">Node1216sadi20120113.JPG</Answer> </AnswerSet></Answers> XSLT is <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:param name="NodeID"></xsl:param> <xsl:param name="NodeType"></xsl:param> <xsl:param name="NodeVirtual"></xsl:param> <xsl:param name="NodeName"></xsl:param> <xsl:param name="NodeTypeID"></xsl:param> <xsl:param name="ParentID"></xsl:param> <xsl:output indent="yes"/> <xsl:template match="Answers"> <Node> <!--NodeID--> <xsl:element name="NodeID"> <xsl:value-of select="$NodeID"/> </xsl:element> <!--NodeType--> <xsl:element name="NodeType"> <xsl:value-of select="$NodeType"/> </xsl:element> <!--NodeTypeID--> <xsl:element name="NodeTypeID"> <xsl:value-of select="$NodeTypeID"/> </xsl:element> <!--NodeVirtual--> <xsl:element name="NodeVirtual"> <xsl:value-of select="$NodeVirtual"/> </xsl:element> <!--NodeVirtual--> <xsl:element name="NodeName"> <xsl:value-of select="$NodeName"/> </xsl:element> <!--ParentID--> <xsl:element name="ParentID"> <xsl:value-of select="$ParentID"/> </xsl:element> <xsl:apply-templates select="AnswerSet/Answer[1]"/> </Node> </xsl:template> <xsl:template match="AnswerSet/Answer[not(@type = 'list') and not(@RegionName)]"> <xsl:element name="{@questionId}"> <xsl:value-of select="."/> </xsl:element> <xsl:apply-templates select="following-sibling::Answer[1]"/> </xsl:template> <xsl:template match="AnswerSet/Answer[(@RegionName)]"> <xsl:element name="{@RegionName}"> <xsl:element name="{@questionId}"> <xsl:if test="@type = 'list'"> <Items> <xsl:value-of select="."/> </Items> </xsl:if> <xsl:if test="not(@type = 'list')"> <xsl:value-of select="."/> </xsl:if> </xsl:element> <xsl:apply-templates select="." mode="Regionlist"/> </xsl:element> <xsl:variable name="next1" select="following-sibling::Answer[@RegionName = current()/@RegionName and @RepeatRegion != current()/@RepeatRegion][1]"/> <xsl:if test="$next1"> <xsl:apply-templates select="$next1"/> </xsl:if> <xsl:apply-templates select="following-sibling::Answer[not(@RegionName = current()/@RegionName)][1]"/> </xsl:template> <!--<xsl:template match="AnswerSet/Answer[(@RegionName)]" mode="RepeatRegionID"> <xsl:element name="{@RegionName}"> <xsl:element name="{@questionId}"> <xsl:if test="@type = 'list'"> <Items> <xsl:value-of select="."/> </Items> </xsl:if> <xsl:if test="not(@type = 'list')"> <xsl:value-of select="."/> </xsl:if> </xsl:element> <xsl:apply-templates select="." mode="Regionlist"/> </xsl:element> </xsl:template>--> <xsl:template match="AnswerSet/Answer" mode="Regionlist"> <xsl:variable name="next" select="following-sibling::Answer[1][@RegionName = current()/@RegionName and @RepeatRegion = current()/@RepeatRegion]"/> <xsl:if test="$next"> <xsl:element name="{($next)[1]/@questionId}"> <xsl:if test="($next)[1]/@type = 'list'"> <Items> <xsl:value-of select="($next)[1]/node()[1]"/> </Items> </xsl:if> <xsl:if test="not(($next)[1]/@type = 'list')"> <xsl:value-of select="($next)[1]/node()[1]"/> </xsl:if> </xsl:element> <xsl:apply-templates select="$next" mode="Regionlist"/> </xsl:if> </xsl:template> <xsl:template match="AnswerSet/Answer[@type = 'list' and not(@RegionName)]"> <xsl:element name="{@questionId}"> <Items> <xsl:value-of select="."/> </Items> <xsl:apply-templates select="." mode="list"/> </xsl:element> <xsl:apply-templates select="following-sibling::Answer[not(@questionId = current()/@questionId) and not(@RegionName)][1]"/> </xsl:template> <xsl:template match="AnswerSet/Answer" mode="list"> <xsl:variable name="next" select="following-sibling::Answer[1][@questionId = current()/@questionId]"/> <xsl:if test="$next"> <Items> <xsl:value-of select="$next"/> </Items> <xsl:apply-templates select="$next" mode="list"/> </xsl:if> </xsl:template></xsl:stylesheet> When I apply above XSLT to sample XML it will transform like : <?xml version="1.0" encoding="utf-8"?><Node> <NodeID></NodeID> <NodeType></NodeType> <NodeTypeID></NodeTypeID> <NodeVirtual></NodeVirtual> <NodeName></NodeName> <ParentID></ParentID> <Name>testttttt123</Name> <TesCal>1/26/2012 12:00:00 AM</TesCal> <testPhoto>Node1216sadi20120113.JPG</testPhoto> <Sam> <Testrr>rr111</Testrr> <Testrr1>123456</Testrr1> </Sam> <Sam> <Testrr>rr1112</Testrr> <Testrr1>456789</Testrr1> </Sam> <Sam> <Testrr>rr1113</Testrr> <Testrr1>4577855</Testrr1> </Sam> <Sam> <Testrr></Testrr> <Testrr1></Testrr1> </Sam> <Sam> <Testrr></Testrr> <Testrr1></Testrr1> </Sam> <testPhoto12>Node1216sadi20120113.JPG</testPhoto12> <testPhoto12>Node1216sadi20120113.JPG</testPhoto12> <testPhoto12>Node1216sadi20120113.JPG</testPhoto12> <testPhoto12>Node1216sadi20120113.JPG</testPhoto12> <testPhoto12>Node1216sadi20120113.JPG</testPhoto12></Node> the proble is last node testPhoto12 is generated multiple time but it should be one time only because Questionid="TextPhoto12" is one time only in sample xml. Please can you provice better idea how to generate XSLT properly. Thanks in advance.
×
×
  • Create New...