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 November 17th, 2004, 04:19 PM
Registered User
 
Join Date: Nov 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to rfleming Send a message via Yahoo to rfleming
Default Need to apply to only a specific node based on var

In short, I am trying to loop through one xml and use the info in that to apply xslt docs to an original xml.

Oringal Incoming XML:

<?xml version="1.0" encoding="UTF-8"?>
<Root DocumentType="01">
        <EmployeeData>
           <EmployeeUniqueIdentifier>1054</EmployeeUniqueIdentifier>
                <FirstName>Donald</FirstName>
                <LastName>Duck</LastName>
        </EmployeeData>
        <EmployeeData> <EmployeeUniqueIdentifier>9999</EmployeeUniqueIdentifier>
                <FirstName>Daffy</FirstName>
                <LastName>Duck</LastName>
        </EmployeeData>
        <EmployeeData>
                <EmployeeUniqueIdentifier>9998</EmployeeUniqueIdentifier>
                <FirstName>Mickey</FirstName>
                <LastName>Mouse</LastName>
        </EmployeeData>
</Root>

I first use this XSLT to create a metadata XML document:

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

<xsl:param name="Employees">
    <xsl:value-of select="count(//EmployeeData)"/>
</xsl:param>

<xsl:template match="/">
        <xsl:for-each select="//EmployeeData">
            <__service __serviceType="EmployeeMaint">
            <xpath>//Employee(<xsl:number value="position()" format="1"/>)</xpath>
            <xslt>Single_EmpMaint.xslt</xslt>
            </__service>
    </xsl:for-each>
</xsl:template>

</xsl:stylesheet>

Applied to the original XML outputs(to a memory string variable):


<?xml version="1.0" encoding="UTF-8"?>
<__service __serviceType="EmployeeMaint">
    <xpath>//Employee(1)</xpath>
    <xslt>Single_EmpMaint.xslt</xslt>
</__service>
<__service __serviceType="EmployeeMaint">
    <xpath>//Employee(2)</xpath>
    <xslt>Single_EmpMaint.xslt</xslt>
</__service>
<__service __serviceType="EmployeeMaint">
    <xpath>//Employee(3)</xpath>
    <xslt>Single_EmpMaint.xslt</xslt>
</__service>


I am looping through this xml string (using .Net)
And for each "serviceType", I want to apply the style sheet in the <xslt/> to an original XML Doc but have it apply to only the node specified.

Single_EmpMain.xslt Stylesheet:

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


    <xsl:template match="/">
        <__InSite __version="1.1">
            <__service __serviceType="EmployeeMaint">
                <__perform>
                    <__eventName>BscSetAction</__eventName>
                </__perform>
                <__inputData>
                    <ObjectChanges>
                        <Name>
                            <xsl:value-of select="FirstName"/>
                        </Name>
                            <LastName>
                                <xsl:value-of select="LastName" />
                            </LastName>
                        <Description>Test</Description>
                    </ObjectChanges>
                </__inputData>
                <__execute/>
                <__requestData>
                    <CompletionMsg/>
                </__requestData>
            </__service>
        </__InSite>
    </xsl:template>
</xsl:stylesheet>

I believe somehow I should have a parameter in the second stylesheet that 'looks up' the node specified in the service_type xml doc, but not sure how to do this? I've been researching with-param's and params, but nothing is quite like this.. I don't have to stick to this format, it's just what I am given to work with. The .Net application though is looping through the nodes of the service type and my challenge is to get it to apply the xsly style sheet to the correct node, one at a time. It then is spitting out a seperate file for each employee. (XSLT 2.0) isn't an option here.

I heard there was a way to get XSLT 1.0 to split out different files, but haven't found it. I am not sure which way is the best here.

Any help or ideas would be greatly appreciated!

Thanks!
:D
Russ

Thanks!

Russell H. Fleming, Jr.
 
Old November 17th, 2004, 05:16 PM
Authorized User
 
Join Date: Nov 2004
Posts: 81
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to jkmyoung
Default

lookup: use the document function
eg. <xsl:variable name="LOOKUPDOC" select="document('service_type.xml')"/>

XSLT 1.0 does not support multiple document outputs. If you're using msxml, you're stuck! You'd have to do it in a non-xslt way. I don't think pure XSLT 2.0 supports multiple documents with variable names either...

Moreover, evaluating xpaths like that would require saxon:evaluate or some other complicated extension function.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Not outputting a specific node zach_1988 XSLT 3 December 2nd, 2008 10:49 AM
Introducing parent node to specific siblings Frimann XSLT 11 July 3rd, 2008 03:20 PM
Jumping to specific record in FormView based on ID peter0480 ASP.NET 2.0 Basics 5 June 18th, 2007 04:37 AM
Copy specific data in specific cells of sheet2 yogeshyl Excel VBA 1 May 14th, 2007 07:40 AM
Using a var into the name of another var or field. guizero Access VBA 3 May 30th, 2006 03:47 PM





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