XSL match some but not all

Posted by Willb on Stack Overflow See other posts from Stack Overflow or by Willb
Published on 2011-03-17T16:07:36Z Indexed on 2011/03/17 16:10 UTC
Read the original article Hit count: 195

Filed under:
|

I have a solution from an earlier post that was kindly provided by Dimitre Novatchev.

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:my="my:my">
      <xsl:output method="xml" version="1.0" encoding="iso-8859-1" indent="yes"/>
      <xsl:key name="kPhysByName" match="KB_XMod_Modules" use="Physician"/>
      <xsl:template match="/">
            <result>
                  <xsl:apply-templates/>
            </result>
      </xsl:template>
      <xsl:template match="/*/*/*[starts-with(name(), 'InfBy')]">
            <xsl:variable name="vCur" select="."/>
            <xsl:for-each select="document('doc2.xml')">
                  <xsl:variable name="vMod" select="key('kPhysByName', $vCur)"/>
                  <xsl:copy>
                        <items>
                              <item>
                                    <label>
                                          <xsl:value-of select="$vMod/Physician"/>
                                    </label>
                                    <value>
                                          <xsl:value-of select="$vMod/XModID"/>
                                    </value>
                              </item>
                        </items>
                  </xsl:copy>
            </xsl:for-each>
      </xsl:template>
</xsl:stylesheet>

I now need to use additional fields in my source XML and need the existing labels intact but I'm having problems getting this going.

<instance>
      <NewTag>Hello</newTag1>
      <AnotherNewTag>Everyone</AnotherNewTag>
      <InfBy1>Dr Phibes</InfBy1>
      <InfBy2>Dr X</InfBy2>
      <InfBy3>Dr Chivago</InfBy3>
</instance>

It drops the additional labels and outputs

<result xmlns:my="my:my">
      HelloEveryone 
      <items>
            <item>
                  <label>Dr Phibes</label>
                  <value>60</value>
            </item>
      </items> ...

I've been experimenting a lot with

<xsl:otherwise>
   <xsl:copy-of select=".">
   </xsl:copy-of>
</xsl:otherwise>

but being an xsl newbie I can't seem to get this to work. I've a feeling I'm barking up the wrong tree!

Does anyone have any ideas?

Thanks,

Will

© Stack Overflow or respective owner

Related posts about Xml

Related posts about xslt