ImageMagick - Add filename, date and time at the bottom of image

REM ##########################################################
REM Make a copy of the original image and then add filename, date and time at the bottom of the copy(*%suffix%).
REM This script was created because I need to know the filename of the printed image.
REM It requires convert.exe and identify.exe.
REM ##########################################################
SET imgExt=jpg
SET suffix=.tx1.%imgExt%
 
del /q *%suffix%
 
FOR /F "delims=" %%i IN ('dir /b *.%imgExt%') DO (CALL :addlabel "%%i")
GOTO EOF
 
:addlabel
SET filename=%1

XSLT - xsltproc

Description xsltproc is a command line XSLT processor. It is used to apply XSL sheet on XML files.

Commands To get all options available for xsltproc, run

xsltproc --help

Apply XSL sheet on XML file:

xsltproc Data.xsl Data.xml > Data.output.txt

Passing string parameters into XSL sheet:

xsltproc --stringparam filename "my filename string" Data.xsl Data.xml > Data.output.txt

XSLT - Using XPath's text() function

The XML file:

<?xml version="1.0" encoding="UTF-8"?>
<root>
  <textarea name="123">a</textarea>
  <textarea name="123">b</textarea>
  <textarea name="123">a</textarea>
  <textarea name="123">c</textarea>
  <textarea name="555">a</textarea>
</root>

The XSL below shows how to use text() in XPath:

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

XSLT - How to handle apostrophe and quote in XSLT

The XML sample

<?xml version="1.0" encoding="UTF-8"?>
<root>
  <textarea name="123'_a">apostrophe: 123'_a</textarea>
  <textarea name="123">b</textarea>
  <textarea name="123">a</textarea>
  <textarea name="123'_&quot;_a">apostrophe and quote: 123'_&quot;_a</textarea>
  <textarea name="123345">c</textarea>
  <textarea name="555">a</textarea>    
</root>

The XSL codes:

<?xml version="1.0" encoding="UTF-8"?>
<!--
Below are examples showing how to handle apostrophe and quote in XSLT
-->

XSLT - Remove Namespace

<?xml version="1.0" encoding="UTF-8"?>
<!-- Remove Namespace -->
<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:template match="*">
      <!-- remove element prefix (if any) -->
      <xsl:element name="{local-name()}">
        <!-- process attributes -->
        <xsl:for-each select="@*">
          <!-- remove attribute prefix (if any) -->
          <xsl:attribute name="{local-name()}">
            <xsl:value-of select="."/>

XSLT - Remove Element Without Child Nodes

<?xml version="1.0" encoding="UTF-8"?>
<!-- Remove Element Without Child Nodes -->
<!-- Only the 1st level is removed. -->
<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:template match="*">
        <xsl:if test="count(@*) &gt; 0 or count(node()) &gt; 0">
            <xsl:copy>
                <xsl:apply-templates select="@* | node()"/>
            </xsl:copy>
        </xsl:if>
    </xsl:template>
    <xsl:template match="@* | text()">

XSLT - Remove attributes or / and nodes

<?xml version="1.0" encoding="UTF-8"?>
<!-- Remove unwanted attributes or/and nodes -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
    <xsl:output method="xml" encoding="UTF-8" indent="yes"/>
 
    <!-- Copy everything -->
    <xsl:template match="@*|node()|text()|comment()|processing-instruction()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()|text()|comment()|processing-instruction()"/>
        </xsl:copy>
    </xsl:template>
 

XSLT - Loops

Decrement Looping

<?xml version="1.0" encoding="UTF-8"?>
<!-- Decrement Looping: Recursively decrementing specified value down to 1. -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
    <xsl:output method="text" encoding="UTF-8"/>
 
    <xsl:template match="/">
        <!-- Calling DecrementLooping template -->
        <xsl:call-template name="DecrementLooping">
          <xsl:with-param name="i" select="9"/>
        </xsl:call-template>
     </xsl:template>

XSLT - Indent content of XML file

<?xml version="1.0" encoding="UTF-8"?>
<!--
Description: Indent the content of the XML file.
-->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
  <xsl:output method="xml" encoding="UTF-8"/><!--Instruct how to output-->
 
  <xsl:param name="indent-increment" select="'   '"/>
  <xsl:template match="*">
    <xsl:param name="indent" select="'&#xA;'"/>
    <xsl:value-of select="$indent"/>
    <xsl:copy>
      <xsl:copy-of select="@*"/>
      <xsl:apply-templates>

XSLT - Copy XML file without comments

<?xml version="1.0" encoding="UTF-8"?>
<!-- 

Pages

Subscribe to OpenWritings.net RSS