xsl-list
[Top] [All Lists]

[xsl] starts-with on more than one item

2008-05-27 14:51:27
Using Saxon-B 9.0 on Windows.  I have Wrox Beginning XML, Michael
Kay's XSLT 2.0 and XPATH 2.0, and Jeni Tennison's XSLT book and they
remind me how small my brain is.  I am new to XSL.

Here's what I have been trying to do (for 65 hours).  A little
background - I sell and install Cisco Systems gear - routers,
switches, firewalls, IP phones, etc.  I am building a "Scope of Work
Tool", an XSL Stylesheet, that is called from a file named
knowledge.xml (shown below) which inputs a simple xml file with the
document() function called 'myskus.xml' to determine what to output to
HTML.  Once I'm done, a customized Scope of Work (depending on what is
being sold, i.e., what is in myskus.xml) will be generated with the
click of a button.

Right now, I'm stuck trying to simply get started with this ambitious
endeavor.  All I am trying to do here is to output the <name> from
knowledge.xml for each sku in myskus.xml that starts-with the <code>
corresponding to the <name>.  So that the output html file says, "Your
proposal includes Cisco phones, Cisco routers, Cisco switches."
Putting an "and" before the last <name> is a different battle for a
different day.

myskus.xml looks like below and will differ based on each deal that I
sell - it's a list pf part numbers, or "sku's":

<?xml version="1.0"?>
<skus>
<sku>WS-C3750G-24PS-S</sku>
<sku>CP-7937G</sku> <!--one flavor of Cisco phone-->
<sku>CP-7941G</sku> <!--another flavor of Cisco phone-->
<sku>VG224</sku>
<sku>CISCO2811-V/K9</sku>
</skus>

OK, now for the xml file called knowledge.xml.  This has my
<knowledge> as the outermost element and <part> children.  The idea is
that each family of parts has specific verbiage that goes in to the
various phases of the installation process (the SOW), e.g., if the BOM
contains phones, we need the SOW to talk about how we <discovery>
determine the call forwarding parameters of each phone </discovery>
<stage>apply the decals to each phone and POST test each phone</stage>
<install> will place each phone at it's proper location and plug it in
to wall jack </install> <verify> will call to and from each phone to
ensure operation </verify>, etc.  The knowledge.xml file looks
something like this:


<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="testXsl.xsl"?>
<knowledge>
    <part>
        <code>CP-</code> <!--All Cisco phone part#'s begin with CP--->
        <name>Cisco phones</name>
        <abbreviation>handsets</abbreviation>
        <discovery>call forwarding destinations</discovery>
        <verify>Out-dialing and In-dialing to a single phone in each
configured class of service ensures a working dialplan and handset
configuration.  </verify>
        <responsibility>unbox, assemble, and place phones at their
final locations</responsibility>
    </part>
    <part>
        <code>CISCO</code> <!--All Cisco router part#'s begin with CISCO--->
        <name>Cisco routers</name>
        <abbreviation>routers</abbreviation>
        <discovery>routing protocols to be enabled</discovery>
    </part>
    <part>
        <code>WS-C</code> <!--All Cisco Ethernet switches part#'s
begin with WS-C--->
        <name>Cisco switches</name>
        <abbreviation>switches</abbreviation>
        <discovery>VLAN assignments</discovery>
        <responsibility>connect all patch cords between switches and
patch panels</responsibility>
</part>
</knowledge>

OK, Moving on (sorry for being verbose)...  I am stuck here - on the
style sheet, of course.  It's titled testXsl.xsl.  Below is what I've
got.

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
 xmlns:xs="http://www.w3.org/2001/XMLSchema"; exclude-result-prefixes="xs"
 version="2.0" >
<xsl:key name="sku" match="knowledge/part" use="code" />
<xsl:variable name="skus" as="xs:string*"
select="distinct-values(/knowledge/part/code)" />

<xsl:template match="/">
 <html>
  <head>
   <title>Test Document</title>
  </head>
  <body>
   <H1>Executive Summary</H1>
<p>Your proposal includes
<xsl:for-each select="document('mySkus.xml')/skus">
<xsl:if test="starts-with('.', $skus)">
<xsl:value-of select="key('sku', '.')/name" />
</xsl:if>
</xsl:for-each>
</p>
  </body>
 </html>
</xsl:template>
</xsl:stylesheet>

Saxon tells me:
XPTY0004: A sequence of more than one item is not allowed as the
second argument of
  starts-with() ("CP-", "ATA186-", ...)
Transformation failed: Run-time errors were reported

I need to output <name> corresponding to <code> that starts-with <sku>
in myskus.xml.  Please help me.

Thank you for listening.

- Ronnie

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>