Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 29th, 2006, 03:42 PM
Authorized User
 
Join Date: Mar 2006
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default Correct my xslt for data substitution

hi experts,

I have xhtml file as 1 node in my xml and data as 1 node in the same xml.

I am trying to add attribute value in all text fields of html using data present in xml.

<Main>
<Errored>
         <StudentRecord>......................</StudentRecord>
          <StudentRecord>.....................</StudentRecord>
          <StudentRecord>.....................</StudentRecord>
          <StudentRecord>.....................</StudentRecord>
</Errored>
<FileData>
         <html>........................</html>
</FileData>
My input xml for html has many studentrecord nodes but i have to substitite the value of matching SSN number record only.
i have xslt code substituting 1 record but it is not working if i add check for SSN number since there is conflict of nodes i guess.I think apply-templates will help but i am not very good in applying templates.Please correct my xslt.

I am displaying all the errors in particular student record on top of my html and it is working fine.I have error attribute in each element og Student Record with proper message if the child data is not correct.
Here is my xslt
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">
    <Main>
      <Data type="">
        <xsl:apply-templates/>
      </Data>
    </Main>
  </xsl:template>
  <xsl:template match="@* | node()[ancestor-or-self::FileData[@fileName='Student.html']/html]">
    <xsl:copy>
      <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>
  </xsl:template>
  <xsl:template match="node()[not(ancestor-or-self::FileData[@fileName='Student.html']/html)]">
    <xsl:apply-templates select="node()"/>
  </xsl:template>
  <xsl:template match="//table[@id='error']">
    <xsl:param name="StudentSSN" select="'345355353'"/>
    <xsl:param name="StudentKey" select="'StudentPin345'"/>
    <xsl:param name="StudentPin" select="'2619345'"/>
    <table id="error">
      <tr class="errorText">
        <xsl:if test="count(//Errored/*)&gt;0">
          <xsl:for-each select="//Errored/StudentRecord//*">
            <xsl:if test ="SSN=$StudentSSN or Student_PIN=$StudentPin or Local_Student_Key=$StudentKey" >
              <xsl:apply-templates/>
            </xsl:if>
          </xsl:for-each>
        </xsl:if>
      </tr>
    </table>
  </xsl:template>
  <xsl:template match="//Errored/StudentRecord//*">
    <xsl:if test="''!=@error">
      <td >
        <xsl:value-of select="@error"/>
      </td>
    </xsl:if>
  </xsl:template>
  <xsl:template match="//input[@type='text']">
    <xsl:param name="StudentSSN" select="'345355353'"/>
    <xsl:param name="StudentKey" select="'StudentPin345'"/>
    <xsl:param name="StudentPin" select="'2619345'"/>

    <xsl:for-each select="//Errored/StudentRecord//*">

      <xsl:if test="SSN=$StudentSSN">

        <xsl:apply-templates/>
      </xsl:if>

    </xsl:for-each>

  </xsl:template>

  <xsl:template match="//input[@type='text']">
    <input>
      <xsl:copy-of select="@*"/>
      <xsl:attribute name="value">
        <xsl:if test="@name='SchoolID'">
          <xsl:value-of select="'LAURA'"/>
        </xsl:if>

      </xsl:attribute>
    </input>
  </xsl:template>

</xsl:stylesheet>

Instead of LAURA i want to pass data from studentrecord xml where SSN=?

Please correct my xslt


Thanks







Similar Threads
Thread Thread Starter Forum Replies Last Post
Variable substitution in logging.properties Gap_Tooth Apache Tomcat 0 July 21st, 2008 02:50 PM
Trouble with getting the correct data after UPDATE Hammad Access ASP 0 January 10th, 2005 07:52 PM
Trouble with getting the correct data after UPDATE Hammad Classic ASP Databases 3 January 8th, 2005 09:57 AM
Substitution for CodeContextObject MKri VB.NET 2002/2003 Basics 0 August 20th, 2004 03:38 AM
Data Type error but it is the correct type Mitch SQL Server 2000 2 March 19th, 2004 11:31 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.