2
7 Comments

Anyone familiar with XSLT? Can't figure something out!

I'm not sure if this type of question is even allowed on this site but I can't seem to get help from anywhere else. I'm needing help in creating a product type of page where the "products" are three columns wide by X amount of rows. ANY help would be appreciated! Please delete if not allowed! Thanks in advance!

on February 10, 2021
  1. 1

    I am familiar with XSLT - but the question does not really give enough information to help you.

    1. 1

      Basically what I'm needing to do is take an XML document that has, for this instance, 6 nodes in it (there could be more) and using Bootstrap, create a 3x6 grid style layout.

      What I am needing the HTML to look like at the end is this...

      <div class="card-group scrollable">

      <div class="card p-2 m-2 border border-primary rounded">
      <img class="card-img-top" src="{VideoThumbnailPath}" alt="Card Thumbnail"/>
      <div class="card-body d-flex flex-column">
      <h5 class="card-title">
      <xsl:value-of select="VideoTitle"/>
      </h5>
      <p class="card-text">
      <xsl:value-of select="VideoDescription"/>
      </p>
      <button type="button" class="btn btn-lg btn-block btn-primary mt-auto">Start Training</button>
      </div>
      </div>
      <div class="card p-2 m-2 border border-primary rounded">
      <img class="card-img-top" src="{VideoThumbnailPath}" alt="Card Thumbnail"/>
      <div class="card-body d-flex flex-column">
      <h5 class="card-title">
      <xsl:value-of select="VideoTitle"/>
      </h5>
      <p class="card-text">
      <xsl:value-of select="VideoDescription"/>
      </p>
      <button type="button" class="btn btn-lg btn-block btn-primary mt-auto">Start Training</button>
      </div>
      </div>
      <div class="card p-2 m-2 border border-primary rounded">
      <img class="card-img-top" src="{VideoThumbnailPath}" alt="Card Thumbnail"/>
      <div class="card-body d-flex flex-column">
      <h5 class="card-title">
      <xsl:value-of select="VideoTitle"/>
      </h5>
      <p class="card-text">
      <xsl:value-of select="VideoDescription"/>
      </p>
      <button type="button" class="btn btn-lg btn-block btn-primary mt-auto">Start Training</button>
      </div>
      </div>
      </div>

      My Problem is that I can't get the first div (<div class="card-group scrollable">) to end after three xml nodes have been looped.

      I hope this is okay to post! I know it's a lot. I'm willing to email it back and forth too if need be. Thanks for your help!

      1. 1

        Doing this here is all but ideal. IIUC you want to turn:

        <products>
          <product id="1"/>
          <product id="2"/>
          <product id="3"/>
          <product id="4"/>
        </products>
        

        into something along the lines of

        <div>
          <div>product 1<div>
          <div>product 2<div>
          <div>product 3<div>
        </div>
        <div>
          <div>product 4<div>
        </div>
        

        Correct?

        1. 1

          Essentially, yes.

          1. 2

            XSLT is FP. Have a look at this SO post.

            That said I don't think it's a good idea to do this in XSLT. It's better to transform the node into a list of products and then use CSS to lay them out the way you want. This can be done quite easily with CSS grid or flexbox.

  2. 1

    I’d recommend that you use a framework to help. Bootstrap, Tailwind and Foundation are all popular. You can also purchase a boilerplate theme that you can modify for a few dollars which are typically made from other indie hackers. Good luck.

    1. 1

      I'm using Bootstrap as my framework. Thanks!