Click here to Skip to main content
14,740,560 members
Home » Discussions » XML / XSL
   

XML / XSL

 
AnswerRe: Transform XML Pin
TML6-Jul-17 11:50
MemberTML6-Jul-17 11:50 
Questionsaving a file to the internet. Pin
felixjrz198531-May-17 22:54
Memberfelixjrz198531-May-17 22:54 
SuggestionRe: saving a file to the internet. Pin
Richard MacCutchan31-May-17 23:32
mveRichard MacCutchan31-May-17 23:32 
GeneralRe: saving a file to the internet. Pin
felixjrz19851-Jun-17 1:43
Memberfelixjrz19851-Jun-17 1:43 
GeneralRe: saving a file to the internet. Pin
Richard MacCutchan1-Jun-17 2:03
mveRichard MacCutchan1-Jun-17 2:03 
GeneralRe: saving a file to the internet. Pin
Gerry Schmitz1-Jun-17 4:20
mveGerry Schmitz1-Jun-17 4:20 
AnswerRe: saving a file to the internet. Pin
Terry Perez11-Sep-17 4:41
MemberTerry Perez11-Sep-17 4:41 
QuestionXSLT passing a variable to starts-with Pin
bjmallon13-Feb-17 15:03
Memberbjmallon13-Feb-17 15:03 
I've got an XML file full of user details including 'FirstName', 'Surname' and 'StreetAddress'.

Currently my XSL file has a template (SurnameAlphabetGrouping) that groups users by the first character of the Surname element's value. I've only provided the process for 'A' to save space. All 26 letters are processed.

<xsl:template name="SurnameAlphabetGrouping">
    <xsl:variable name="AMatch" select="/Users/User[starts-with(Surname, 'A')]"/>
    <xsl:variable name="ACount" select="count($AMatch)"/>
    <xsl:if test="$ACount > 0">
      <h2>
        <a href="javascript:void(0)" class="dsphead" onclick="dsp(this)">
          <span class="dspchar">+</span> A (<xsl:value-of select="$ACount"/>)
        </a>
      </h2>
      <div class="dspcont">
        <table border="1" cellpadding="1" cellspacing="1">
          <tr>
            <xsl:call-template name="HeadingRow"/>
          </tr>

          <xsl:for-each select="/Users/User[starts-with(Surname, 'A')]">
            <xsl:sort select="Surname"/>
            <xsl:call-template name="UserRow"/>
          </xsl:for-each>
        </table>
      </div>
    </xsl:if>
  </xsl:template>


That's all well and good. But now that I've got it working that way, I really want to make it smarter (i.e. cut down the code), so I'm trying to build a template that can take the required character as a parameter.

I've got a variable (Letters) that carries tokens for the 26 letters of the alphabet:
<xsl:variable name="Letters">
    <xsl:call-template name="tokenise">
      <xsl:with-param name="string" select ="'A B C D E F G H I J K L M N O P Q R S T U V W X Y Z'"/>
      <xsl:with-param name="delimeters" select="' '"/>
    </xsl:call-template>
  </xsl:variable>


I'm then attempting to process each token, passing it to the template as a parameter:
<xsl:for-each select="msxsl:node-set($Letters)/token">
  <xsl:variable name="currToken" select ="./node()[1]"/>
  <xsl:call-template name="ListSurnameStartsWith">
    <xsl:with-param name="character" select="$currToken"/>
  </xsl:call-template>
</xsl:for-each>


This is the template as it stands at the moment:
<xsl:template name="ListSurnameStartsWith">
    <xsl:param name="character" select="''"/>
    <xsl:variable name="charMatch" select="/Users/User[starts-with(Surname, $character)]"/>    
    <xsl:variable name="charCount" select="count($charMatch)"/>
    
      <xsl:if test="$charCount > 0">
      <h2>
        <a href="javascript:void(0)" class="dsphead" onclick="dsp(this)">
          <span class="dspchar">+</span> <xsl:value-of select="$character"/> (<xsl:value-of select="$charCount"/>)
        </a>
      </h2>
      <div class="dspcont">
        <table border="1" cellpadding="1" cellspacing="1">
          <tr>
            <xsl:call-template name="HeadingRow"/>
          </tr>

          <xsl:for-each select="/Users/User[starts-with(Surname, $character)]">
            <xsl:sort select="Surname"/>
            <xsl:call-template name="UserRow"/>
          </xsl:for-each>
        </table>
      </div>
    </xsl:if>
  </xsl:template>



'currToken' is getting the value I want. It's landing in the 'ListSurnameStartsWith' template just fine, but 'charMatch' just comes back blank all the time, meaning I can't get a meaningful count to test whether the output needs to be generated. The later '
AnswerRe: XSLT passing a variable to starts-with Pin
Richard Deeming14-Feb-17 3:32
mveRichard Deeming14-Feb-17 3:32 
GeneralRe: XSLT passing a variable to starts-with Pin
bjmallon16-Feb-17 19:45
Memberbjmallon16-Feb-17 19:45 
GeneralRe: XSLT passing a variable to starts-with Pin
Richard Deeming17-Feb-17 2:48
mveRichard Deeming17-Feb-17 2:48 
GeneralRe: XSLT passing a variable to starts-with Pin
bjmallon20-Feb-17 23:55
Memberbjmallon20-Feb-17 23:55 
GeneralRe: XSLT passing a variable to starts-with Pin
Richard Deeming21-Feb-17 2:42
mveRichard Deeming21-Feb-17 2:42 
GeneralRe: XSLT passing a variable to starts-with Pin
bjmallon21-Feb-17 11:24
Memberbjmallon21-Feb-17 11:24 
QuestionHow to generate XML file with serialisation in vb.net Pin
Member 1280320219-Oct-16 9:06
MemberMember 1280320219-Oct-16 9:06 
Rant[REPOST] How to generate XML file with serialisation in vb.net Pin
Richard Deeming19-Oct-16 10:28
mveRichard Deeming19-Oct-16 10:28 
QuestionTransform the date format from yyyy/mm/dd to mm/dd/yyyy Pin
Member 1278840611-Oct-16 16:21
MemberMember 1278840611-Oct-16 16:21 
AnswerRe: Transform the date format from yyyy/mm/dd to mm/dd/yyyy Pin
Richard Deeming12-Oct-16 4:26
mveRichard Deeming12-Oct-16 4:26 
QuestionRead xml string Pin
trungysp198610-Oct-16 15:48
Membertrungysp198610-Oct-16 15:48 
AnswerRe: Read xml string Pin
Richard MacCutchan10-Oct-16 22:54
mveRichard MacCutchan10-Oct-16 22:54 
AnswerRe: Read xml string Pin
Swinkaran11-Oct-16 17:09
professionalSwinkaran11-Oct-16 17:09 
QuestionXML Pin
Member 1273144310-Sep-16 4:41
MemberMember 1273144310-Sep-16 4:41 
AnswerRe: XML Pin
OriginalGriff10-Sep-16 4:44
mveOriginalGriff10-Sep-16 4:44 
GeneralRe: XML Pin
Member 1273144310-Sep-16 4:48
MemberMember 1273144310-Sep-16 4:48 
GeneralRe: XML Pin
Member 1273144310-Sep-16 4:52
MemberMember 1273144310-Sep-16 4:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.